[Midnightbsd-cvs] src [7901] trunk/lib/libedit: remerge some things from netbsd
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Wed Sep 14 15:09:03 EDT 2016
Revision: 7901
http://svnweb.midnightbsd.org/src/?rev=7901
Author: laffer1
Date: 2016-09-14 15:09:03 -0400 (Wed, 14 Sep 2016)
Log Message:
-----------
remerge some things from netbsd
Modified Paths:
--------------
trunk/lib/libedit/chared.c
trunk/lib/libedit/chared.h
trunk/lib/libedit/editline.3
trunk/lib/libedit/el.h
trunk/lib/libedit/makelist
trunk/lib/libedit/read.c
trunk/lib/libedit/sig.c
trunk/lib/libedit/sig.h
trunk/lib/libedit/tokenizer.c
Modified: trunk/lib/libedit/chared.c
===================================================================
--- trunk/lib/libedit/chared.c 2016-09-14 19:01:28 UTC (rev 7900)
+++ trunk/lib/libedit/chared.c 2016-09-14 19:09:03 UTC (rev 7901)
@@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $NetBSD: chared.c,v 1.25 2005/08/08 01:41:30 christos Exp $
+ * $NetBSD: chared.c,v 1.27 2009/02/15 21:55:23 christos Exp $
*/
#if !defined(lint) && !defined(SCCSID)
@@ -59,12 +59,12 @@
{
c_undo_t *vu = &el->el_chared.c_undo;
c_redo_t *r = &el->el_chared.c_redo;
- unsigned int size;
+ size_t size;
/* Save entire line for undo */
size = el->el_line.lastchar - el->el_line.buffer;
vu->len = size;
- vu->cursor = el->el_line.cursor - el->el_line.buffer;
+ vu->cursor = (int)(el->el_line.cursor - el->el_line.buffer);
memcpy(vu->buf, el->el_line.buffer, size);
/* save command info for redo */
@@ -83,7 +83,7 @@
{
c_kill_t *k = &el->el_chared.c_kill;
- memcpy(k->buf, ptr, size +0u);
+ memcpy(k->buf, ptr, (size_t)size);
k->last = k->buf + size;
}
@@ -97,7 +97,7 @@
char *cp;
if (el->el_line.lastchar + num >= el->el_line.limit) {
- if (!ch_enlargebufs(el, num +0u))
+ if (!ch_enlargebufs(el, (size_t)num))
return; /* can't go past end of buffer */
}
@@ -118,7 +118,7 @@
{
if (el->el_line.cursor + num > el->el_line.lastchar)
- num = el->el_line.lastchar - el->el_line.cursor;
+ num = (int)(el->el_line.lastchar - el->el_line.cursor);
if (el->el_map.current != el->el_map.emacs) {
cv_undo(el);
@@ -159,7 +159,7 @@
{
if (el->el_line.cursor - num < el->el_line.buffer)
- num = el->el_line.cursor - el->el_line.buffer;
+ num = (int)(el->el_line.cursor - el->el_line.buffer);
if (el->el_map.current != el->el_map.emacs) {
cv_undo(el);
@@ -375,7 +375,7 @@
/* sanity */
return;
- size = el->el_line.cursor - el->el_chared.c_vcmd.pos;
+ size = (int)(el->el_line.cursor - el->el_chared.c_vcmd.pos);
if (size == 0)
size = 1;
el->el_line.cursor = el->el_chared.c_vcmd.pos;
@@ -529,8 +529,7 @@
}
private void
-ch__clearmacro(el)
- EditLine *el;
+ch__clearmacro(EditLine *el)
{
c_macro_t *ma = &el->el_chared.c_macro;
while (ma->level >= 0)
@@ -542,9 +541,7 @@
* Returns 1 if successful, 0 if not.
*/
protected int
-ch_enlargebufs(el, addlen)
- EditLine *el;
- size_t addlen;
+ch_enlargebufs(EditLine *el, size_t addlen)
{
size_t sz, newsz;
char *newbuffer, *oldbuf, *oldkbuf;
@@ -695,12 +692,12 @@
c_gets(EditLine *el, char *buf, const char *prompt)
{
char ch;
- int len;
+ ssize_t len;
char *cp = el->el_line.buffer;
if (prompt) {
len = strlen(prompt);
- memcpy(cp, prompt, len + 0u);
+ memcpy(cp, prompt, (size_t)len);
cp += len;
}
len = 0;
@@ -721,7 +718,7 @@
case '\010': /* Delete and backspace */
case '\177':
- if (len <= 0) {
+ if (len == 0) {
len = -1;
break;
}
@@ -749,7 +746,7 @@
el->el_line.buffer[0] = '\0';
el->el_line.lastchar = el->el_line.buffer;
el->el_line.cursor = el->el_line.buffer;
- return len;
+ return (int)len;
}
@@ -771,6 +768,6 @@
ptr >= el->el_line.buffer && *ptr != '\n';
ptr--)
continue;
- return (el->el_line.cursor - ptr - 1);
+ return (int)(el->el_line.cursor - ptr - 1);
}
}
Modified: trunk/lib/libedit/chared.h
===================================================================
--- trunk/lib/libedit/chared.h 2016-09-14 19:01:28 UTC (rev 7900)
+++ trunk/lib/libedit/chared.h 2016-09-14 19:09:03 UTC (rev 7901)
@@ -70,7 +70,7 @@
* Undo information for vi - no undo in emacs (yet)
*/
typedef struct c_undo_t {
- int len; /* length of saved line */
+ ssize_t len; /* length of saved line */
int cursor; /* position of saved cursor */
char *buf; /* full saved text */
} c_undo_t;
Modified: trunk/lib/libedit/editline.3
===================================================================
--- trunk/lib/libedit/editline.3 2016-09-14 19:01:28 UTC (rev 7900)
+++ trunk/lib/libedit/editline.3 2016-09-14 19:09:03 UTC (rev 7901)
@@ -162,6 +162,11 @@
Returns the line read if successful, or
.Dv NULL
if no characters were read or if an error occurred.
+If an error occurred,
+.Fa count
+is set to \-1 and
+.Dv errno
+contains the error code that caused it.
The return value may not remain valid across calls to
.Fn el_gets
and must be copied if the data is to be retained.
Modified: trunk/lib/libedit/el.h
===================================================================
--- trunk/lib/libedit/el.h 2016-09-14 19:01:28 UTC (rev 7900)
+++ trunk/lib/libedit/el.h 2016-09-14 19:09:03 UTC (rev 7901)
@@ -115,6 +115,7 @@
FILE *el_errfile; /* Stdio stuff */
int el_infd; /* Input file descriptor */
int el_flags; /* Various flags. */
+ int el_errno; /* Local copy of errno */
coord_t el_cursor; /* Cursor location */
char **el_display; /* Real screen image = what is there */
char **el_vdisplay; /* Virtual screen image = what we see */
Modified: trunk/lib/libedit/makelist
===================================================================
--- trunk/lib/libedit/makelist 2016-09-14 19:01:28 UTC (rev 7900)
+++ trunk/lib/libedit/makelist 2016-09-14 19:09:03 UTC (rev 7901)
@@ -141,7 +141,7 @@
#
-fh)
cat $FILES | $AWK '/el_action_t/ { print $3 }' | \
- sort | LC_ALL=C tr 'a-z' 'A-Z' | $AWK '
+ sort | LC_ALL=C tr '[:lower:]' '[:upper:]' | $AWK '
BEGIN {
printf("/* Automatically generated file, do not edit */\n");
printf("#ifndef _h_fcns_c\n#define _h_fcns_c\n");
Modified: trunk/lib/libedit/read.c
===================================================================
--- trunk/lib/libedit/read.c 2016-09-14 19:01:28 UTC (rev 7900)
+++ trunk/lib/libedit/read.c 2016-09-14 19:09:03 UTC (rev 7901)
@@ -235,9 +235,12 @@
el_action_t cmd;
int num;
+ el->el_errno = 0;
do {
- if ((num = el_getc(el, ch)) != 1) /* if EOF or error */
+ if ((num = el_getc(el, ch)) != 1) { /* if EOF or error */
+ el->el_errno = num == 0 ? 0 : errno;
return (num);
+ }
#ifdef KANJI
if ((*ch & 0200)) {
@@ -289,7 +292,14 @@
ssize_t num_read;
int tried = 0;
- while ((num_read = read(el->el_infd, cp, 1)) == -1)
+ again:
+ el->el_signal->sig_no = 0;
+ while ((num_read = read(el->el_infd, cp, 1)) == -1) {
+ if (el->el_signal->sig_no == SIGCONT) {
+ sig_set(el);
+ el_set(el, EL_REFRESH);
+ goto again;
+ }
if (!tried && read__fixio(el->el_infd, errno) == 0)
tried = 1;
else {
@@ -296,7 +306,7 @@
*cp = '\0';
return (-1);
}
-
+ }
return (int)num_read;
}
@@ -403,10 +413,13 @@
int num; /* how many chars we have read at NL */
char ch;
int crlf = 0;
+ int nrb;
#ifdef FIONREAD
c_macro_t *ma = &el->el_chared.c_macro;
#endif /* FIONREAD */
+ if (nread == NULL)
+ nread = &nrb;
*nread = 0;
if (el->el_flags & NO_TTY) {
@@ -427,12 +440,13 @@
if (cp[-1] == '\r' || cp[-1] == '\n')
break;
}
+ if (num == -1)
+ el->el_errno = errno;
el->el_line.cursor = el->el_line.lastchar = cp;
*cp = '\0';
- if (nread)
- *nread = (int)(el->el_line.cursor - el->el_line.buffer);
- return (*nread ? el->el_line.buffer : NULL);
+ *nread = (int)(el->el_line.cursor - el->el_line.buffer);
+ goto done;
}
@@ -443,8 +457,8 @@
(void) ioctl(el->el_infd, FIONREAD, (ioctl_t) & chrs);
if (chrs == 0) {
if (tty_rawmode(el) < 0) {
- if (nread)
- *nread = 0;
+ errno = 0;
+ *nread = 0;
return (NULL);
}
}
@@ -457,6 +471,7 @@
if (el->el_flags & EDIT_DISABLED) {
char *cp;
size_t idx;
+
if ((el->el_flags & UNBUFFERED) == 0)
cp = el->el_line.buffer;
else
@@ -480,11 +495,13 @@
break;
}
+ if (num == -1) {
+ el->el_errno = errno;
+ }
+
el->el_line.cursor = el->el_line.lastchar = cp;
*cp = '\0';
- if (nread)
- *nread = (int)(el->el_line.cursor - el->el_line.buffer);
- return (*nread ? el->el_line.buffer : NULL);
+ goto done;
}
for (num = OKCMD; num == OKCMD;) { /* while still editing this
@@ -617,12 +634,17 @@
/* make sure the tty is set up correctly */
if ((el->el_flags & UNBUFFERED) == 0) {
read_finish(el);
- if (nread)
- *nread = num;
+ *nread = num != -1 ? num : 0;
} else {
- if (nread)
- *nread =
- (int)(el->el_line.lastchar - el->el_line.buffer);
+ *nread = (int)(el->el_line.lastchar - el->el_line.buffer);
}
- return (num ? el->el_line.buffer : NULL);
+done:
+ if (*nread == 0) {
+ if (num == -1) {
+ *nread = -1;
+ errno = el->el_errno;
+ }
+ return NULL;
+ } else
+ return el->el_line.buffer;
}
Modified: trunk/lib/libedit/sig.c
===================================================================
--- trunk/lib/libedit/sig.c 2016-09-14 19:01:28 UTC (rev 7900)
+++ trunk/lib/libedit/sig.c 2016-09-14 19:09:03 UTC (rev 7901)
@@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $NetBSD: sig.c,v 1.14 2009/02/18 15:04:40 christos Exp $
+ * $NetBSD: sig.c,v 1.15 2009/02/19 15:20:22 christos Exp $
*/
#if !defined(lint) && !defined(SCCSID)
@@ -73,6 +73,8 @@
(void) sigaddset(&nset, signo);
(void) sigprocmask(SIG_BLOCK, &nset, &oset);
+ sel->el_signal->sig_no = signo;
+
switch (signo) {
case SIGCONT:
tty_rawmode(sel);
@@ -158,12 +160,12 @@
struct sigaction osa, nsa;
nsa.sa_handler = sig_handler;
+ nsa.sa_flags = 0;
sigemptyset(&nsa.sa_mask);
(void) sigprocmask(SIG_BLOCK, &el->el_signal->sig_set, &oset);
for (i = 0; sighdl[i] != -1; i++) {
- nsa.sa_flags = SIGINT ? 0 : SA_RESTART;
/* This could happen if we get interrupted */
if (sigaction(sighdl[i], &nsa, &osa) != -1 &&
osa.sa_handler != sig_handler)
Modified: trunk/lib/libedit/sig.h
===================================================================
--- trunk/lib/libedit/sig.h 2016-09-14 19:01:28 UTC (rev 7900)
+++ trunk/lib/libedit/sig.h 2016-09-14 19:09:03 UTC (rev 7901)
@@ -61,6 +61,7 @@
typedef struct {
struct sigaction sig_action[ALLSIGSNO];
sigset_t sig_set;
+ volatile sig_atomic_t sig_no;
} *el_signal_t;
protected void sig_end(EditLine*);
Modified: trunk/lib/libedit/tokenizer.c
===================================================================
--- trunk/lib/libedit/tokenizer.c 2016-09-14 19:01:28 UTC (rev 7900)
+++ trunk/lib/libedit/tokenizer.c 2016-09-14 19:09:03 UTC (rev 7901)
@@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $NetBSD: tokenizer.c,v 1.14 2003/12/05 13:37:48 lukem Exp $
+ * $NetBSD: tokenizer.c,v 1.15 2009/02/15 21:55:23 christos Exp $
*/
#if !defined(lint) && !defined(SCCSID)
@@ -198,7 +198,7 @@
ptr = "";
if (ptr == line->cursor) {
cc = tok->argc;
- co = tok->wptr - tok->wstart;
+ co = (int)(tok->wptr - tok->wstart);
}
switch (*ptr) {
case '\'':
@@ -417,7 +417,7 @@
tok_line_outok:
if (cc == -1 && co == -1) {
cc = tok->argc;
- co = tok->wptr - tok->wstart;
+ co = (int)(tok->wptr - tok->wstart);
}
if (cursorc != NULL)
*cursorc = cc;
More information about the Midnightbsd-cvs
mailing list