Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libedit apply apple patches from:



details:   https://anonhg.NetBSD.org/src/rev/783dccf85491
branches:  trunk
changeset: 747274:783dccf85491
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Sep 07 21:24:33 2009 +0000

description:
apply apple patches from:
http://opensource.apple.com/source/libedit/libedit-11/patches/

diffstat:

 lib/libedit/histedit.h          |    6 +-
 lib/libedit/history.c           |  107 ++++++++++++++-
 lib/libedit/readline.c          |  294 ++++++++++++++++++++++++++++++++++++---
 lib/libedit/readline/readline.h |   25 ++-
 4 files changed, 398 insertions(+), 34 deletions(-)

diffs (truncated from 746 to 300 lines):

diff -r 4db11f372d6d -r 783dccf85491 lib/libedit/histedit.h
--- a/lib/libedit/histedit.h    Mon Sep 07 21:07:02 2009 +0000
+++ b/lib/libedit/histedit.h    Mon Sep 07 21:24:33 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: histedit.h,v 1.40 2009/05/11 18:33:30 christos Exp $   */
+/*     $NetBSD: histedit.h,v 1.41 2009/09/07 21:24:33 christos Exp $   */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -204,6 +204,10 @@
 #define        H_SETUNIQUE     20      /* , int);              */
 #define        H_GETUNIQUE     21      /* , void);             */
 #define        H_DEL           22      /* , int);              */
+#define        H_NEXT_EVDATA   23      /* , const int, histdata_t *);  */
+#define        H_DELDATA       24      /* , int, histdata_t *);*/
+#define        H_REPLACE       25      /* , const char *, histdata_t); */
+
 
 
 /*
diff -r 4db11f372d6d -r 783dccf85491 lib/libedit/history.c
--- a/lib/libedit/history.c     Mon Sep 07 21:07:02 2009 +0000
+++ b/lib/libedit/history.c     Mon Sep 07 21:24:33 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: history.c,v 1.33 2009/02/06 14:40:32 sketch Exp $      */
+/*     $NetBSD: history.c,v 1.34 2009/09/07 21:24:33 christos Exp $    */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)history.c  8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: history.c,v 1.33 2009/02/06 14:40:32 sketch Exp $");
+__RCSID("$NetBSD: history.c,v 1.34 2009/09/07 21:24:33 christos Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
@@ -121,6 +121,7 @@
  */
 typedef struct hentry_t {
        HistEvent ev;           /* What we return                */
+       void *data;             /* data                          */
        struct hentry_t *next;  /* Next entry                    */
        struct hentry_t *prev;  /* Previous entry                */
 } hentry_t;
@@ -150,6 +151,9 @@
 private int history_def_insert(history_t *, HistEvent *, const char *);
 private void history_def_delete(history_t *, HistEvent *, hentry_t *);
 
+private int history_deldata_nth(history_t *, HistEvent *, int, void **);
+private int history_set_nth(ptr_t, HistEvent *, int);
+
 #define        history_def_setsize(p, num)(void) (((history_t *)p)->max = (num))
 #define        history_def_getsize(p)  (((history_t *)p)->cur)
 #define        history_def_getunique(p) (((((history_t *)p)->flags) & H_UNIQUE) != 0)
@@ -340,6 +344,31 @@
 }
 
 
+/* history_set_nth():
+ *     Default function to set the current event in the history to the
+ *     n-th one.
+ */
+private int
+history_set_nth(ptr_t p, HistEvent *ev, int n)
+{
+       history_t *h = (history_t *) p;
+
+       if (h->cur == 0) {
+               he_seterrev(ev, _HE_EMPTY_LIST);
+               return (-1);
+       }
+       for (h->cursor = h->list.prev; h->cursor != &h->list;
+           h->cursor = h->cursor->prev)
+               if (n-- <= 0)
+                       break;
+       if (h->cursor == &h->list) {
+               he_seterrev(ev, _HE_NOT_FOUND);
+               return (-1);
+       }
+       return (0);
+}
+
+
 /* history_def_add():
  *     Append string to element
  */
@@ -368,6 +397,24 @@
 }
 
 
+private int
+history_deldata_nth(history_t *h, HistEvent *ev,
+    int num, void **data)
+{
+       if (history_set_nth(h, ev, num) != 0)
+               return (-1);
+       /* magic value to skip delete (just set to n-th history) */
+       if (data == (void **)-1)
+               return (0);
+       ev->str = strdup(h->cursor->ev.str);
+       ev->num = h->cursor->ev.num;
+       if (data)
+               *data = h->cursor->data;
+       history_def_delete(h, ev, h->cursor);
+       return (0);
+}
+
+
 /* history_def_del():
  *     Delete element hp of the h list
  */
@@ -397,8 +444,11 @@
        HistEventPrivate *evp = (void *)&hp->ev;
        if (hp == &h->list)
                abort();
-       if (h->cursor == hp)
+       if (h->cursor == hp) {
                h->cursor = hp->prev;
+               if (h->cursor == &h->list)
+                       h->cursor = hp->next;
+       }
        hp->prev->next = hp->next;
        hp->next->prev = hp->prev;
        h_free((ptr_t) evp->str);
@@ -421,6 +471,7 @@
                h_free((ptr_t)h->cursor);
                goto oomem;
        }
+       h->cursor->data = NULL;
        h->cursor->ev.num = ++h->eventid;
        h->cursor->next = h->list.next;
        h->cursor->prev = &h->list;
@@ -792,6 +843,23 @@
 }
 
 
+private int
+history_next_evdata(History *h, HistEvent *ev, int num, void **d)
+{
+       int retval;
+
+       for (retval = HCURR(h, ev); retval != -1; retval = HPREV(h, ev))
+               if (num-- <= 0) {
+                       if (d)
+                               *d = ((history_t *)h->h_ref)->cursor->data;
+                       return (0);
+               }
+
+       he_seterrev(ev, _HE_NOT_FOUND);
+       return (-1);
+}
+
+
 /* history_next_event():
  *     Find the next event, with number given
  */
@@ -981,11 +1049,42 @@
                retval = 0;
                break;
 
+       case H_NEXT_EVDATA:
+       {
+               int num = va_arg(va, int);
+               void **d = va_arg(va, void **);
+               retval = history_next_evdata(h, ev, num, d);
+               break;
+       }
+
+       case H_DELDATA:
+       {
+               int num = va_arg(va, int);
+               void **d = va_arg(va, void **);
+               retval = history_deldata_nth((history_t *)h->h_ref, ev, num, d);
+               break;
+       }
+
+       case H_REPLACE: /* only use after H_NEXT_EVDATA */
+       {
+               const char *line = va_arg(va, const char *);
+               void *d = va_arg(va, void *);
+               const char *s;
+               if(!line || !(s = strdup(line))) {
+                       retval = -1;
+                       break;
+               }
+               ((history_t *)h->h_ref)->cursor->ev.str = s;
+               ((history_t *)h->h_ref)->cursor->data = d;
+               retval = 0;
+               break;
+       }
+
        default:
                retval = -1;
                he_seterrev(ev, _HE_UNKNOWN);
                break;
        }
        va_end(va);
-       return (retval);
+       return retval;
 }
diff -r 4db11f372d6d -r 783dccf85491 lib/libedit/readline.c
--- a/lib/libedit/readline.c    Mon Sep 07 21:07:02 2009 +0000
+++ b/lib/libedit/readline.c    Mon Sep 07 21:24:33 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: readline.c,v 1.84 2009/07/22 15:57:40 christos Exp $   */
+/*     $NetBSD: readline.c,v 1.85 2009/09/07 21:24:33 christos Exp $   */
 
 /*-
  * Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include "config.h"
 #if !defined(lint) && !defined(SCCSID)
-__RCSID("$NetBSD: readline.c,v 1.84 2009/07/22 15:57:40 christos Exp $");
+__RCSID("$NetBSD: readline.c,v 1.85 2009/09/07 21:24:33 christos Exp $");
 #endif /* not lint && not SCCSID */
 
 #include <sys/types.h>
@@ -70,6 +70,7 @@
 /* readline compatibility stuff - look at readline sources/documentation */
 /* to see what these variables mean */
 const char *rl_library_version = "EditLine wrapper";
+int rl_readline_version = RL_READLINE_VERSION;
 static char empty[] = { '\0' };
 static char expand_chars[] = { ' ', '\t', '\n', '=', '(', '\0' };
 static char break_chars[] = { ' ', '\t', '\n', '"', '\\', '\'', '`', '@', '$',
@@ -118,6 +119,7 @@
 VFunction *rl_completion_display_matches_hook = NULL;
 VFunction *rl_prep_term_function = (VFunction *)rl_prep_terminal;
 VFunction *rl_deprep_term_function = (VFunction *)rl_deprep_terminal;
+KEYMAP_ENTRY_ARRAY emacs_meta_keymap;
 
 /*
  * The current prompt string.
@@ -214,6 +216,22 @@
        return 1;
 }
 
+static const char _dothistory[] = "/.history";
+
+static const char *
+_default_history_file(void)
+{
+       struct passwd *p;
+       static char path[PATH_MAX];
+
+       if (*path)
+               return path;
+       if ((p = getpwuid(getuid())) == NULL)
+               return NULL;
+       strlcpy(path, p->pw_dir, PATH_MAX);
+       strlcat(path, _dothistory, PATH_MAX);
+       return path;
+}
 
 /*
  * READLINE compatibility stuff
@@ -648,9 +666,11 @@
                return(-1);
 
        if (!has_mods) {
-               *result = strdup(aptr? aptr : ptr);
+               *result = strdup(aptr ? aptr : ptr);
                if (aptr)
                        free(aptr);
+               if (*result == NULL)
+                       return -1;
                return(1);
        }
 
@@ -1125,6 +1145,142 @@
        return (max_input_history != INT_MAX);
 }
 
+static const char _history_tmp_template[] = "/tmp/.historyXXXXXX";
+
+int
+history_truncate_file (const char *filename, int nlines)
+{
+       int ret = 0;
+       FILE *fp, *tp;
+       char template[sizeof(_history_tmp_template)];
+       char buf[4096];
+       int fd;
+       char *cp;
+       off_t off;
+       int count = 0;
+       ssize_t left = 0;
+
+       if (filename == NULL && (filename = _default_history_file()) == NULL)
+               return errno;
+       if ((fp = fopen(filename, "r+")) == NULL)
+               return errno;
+       strcpy(template, _history_tmp_template);
+       if ((fd = mkstemp(template)) == -1) {
+               ret = errno;
+               goto out1;
+       }



Home | Main Index | Thread Index | Old Index