Sync some (mostly cosmetical) changes from NetBSD

Makefile,v 1.37
tc1.c v 1.3
Rename TEST/test.c tc1.c

common.c,v 1.23
pass lint on _LP64.

emacs.c,v 1.22
pass lint on _LP64.

filecomplete.h,v 1.8
mv NetBSD ID back from 1.9 as we don't
have the widecharacter support.

prompt.c,v 1.14
prompt.h,v 1.9
term.h,v 1.20
read.h,v 1.6
Update NetBSD version strings

sys.h,v 1.12
Misc sun stuff.

tty.c 1.31
handle EINTR in the termios operations
Allow a single process to control multiple ttys (for pthreads using _REENTRANT)
using multiple EditLine objects.
pass lint on _LP64.
Don't depend on side effects inside an assert

MFC after:	1 week
Obtained from:	NetBSD
This commit is contained in:
Pedro F. Giffuni 2014-07-10 17:52:17 +00:00
parent 58e6549541
commit c4a1f025cf
12 changed files with 80 additions and 39 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.34 2005/05/28 12:02:53 lukem Exp $ # $NetBSD: Makefile,v 1.37 2009/01/18 12:17:49 lukem Exp $
# @(#)Makefile 8.1 (Berkeley) 6/4/93 # @(#)Makefile 8.1 (Berkeley) 6/4/93
# $FreeBSD$ # $FreeBSD$
@ -70,9 +70,9 @@ editline.c: ${OSRCS}
editline.o editline.po editline.So editline.ln: \ editline.o editline.po editline.So editline.ln: \
common.h emacs.h fcns.c fcns.h help.c help.h vi.h common.h emacs.h fcns.c fcns.h help.c help.h vi.h
test.o: ${.CURDIR}/TEST/test.c tc1.o: ${.CURDIR}/TEST/tc1.c
test: test.o libedit.a ${DPADD} ${LIBTERMCAP} test: tc1.o libedit.a ${DPADD} ${LIBTERMCAP}
${CC} ${CFLAGS} ${.ALLSRC} -o ${.TARGET} libedit.a ${LDADD} ${CC} ${CFLAGS} ${.ALLSRC} -o ${.TARGET} libedit.a ${LDADD}
.include <bsd.lib.mk> .include <bsd.lib.mk>

View File

@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1992, 1993\n\
#if !defined(lint) && !defined(SCCSID) #if !defined(lint) && !defined(SCCSID)
static char sccsid[] = "@(#)test.c 8.1 (Berkeley) 6/4/93"; static char sccsid[] = "@(#)test.c 8.1 (Berkeley) 6/4/93";
#endif /* not lint && not SCCSID */ #endif /* not lint && not SCCSID */
__RCSID("$NetBSD: test.c,v 1.18 2005/06/01 11:37:52 lukem Exp $"); __RCSID("$NetBSD: test.c,v 1.3 2009/07/17 12:25:52 christos Exp $");
__FBSDID("$FreeBSD$"); __FBSDID("$FreeBSD$");
/* /*
@ -68,7 +68,7 @@ static void sig(int);
static char * static char *
prompt(EditLine *el) prompt(EditLine *el)
{ {
static char a[] = "Edit$ "; static char a[] = "\1\e[7m\1Edit$\1\e[0m\1 ";
static char b[] = "Edit> "; static char b[] = "Edit> ";
return (continuation ? b : a); return (continuation ? b : a);
@ -143,7 +143,7 @@ main(int argc, char *argv[])
el_set(el, EL_EDITOR, "vi"); /* Default editor is vi */ el_set(el, EL_EDITOR, "vi"); /* Default editor is vi */
el_set(el, EL_SIGNAL, 1); /* Handle signals gracefully */ el_set(el, EL_SIGNAL, 1); /* Handle signals gracefully */
el_set(el, EL_PROMPT, prompt); /* Set the prompt function */ el_set(el, EL_PROMPT_ESC, prompt, '\1');/* Set the prompt function */
/* Tell editline to use this history interface */ /* Tell editline to use this history interface */
el_set(el, EL_HIST, history, hist); el_set(el, EL_HIST, history, hist);
@ -183,7 +183,7 @@ main(int argc, char *argv[])
#endif #endif
if (gotsig) { if (gotsig) {
(void) fprintf(stderr, "Got signal %d.\n", gotsig); (void) fprintf(stderr, "Got signal %d.\n", (int)gotsig);
gotsig = 0; gotsig = 0;
el_reset(el); el_reset(el);
} }

View File

@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $NetBSD: common.c,v 1.19 2006/03/06 21:11:56 christos Exp $ * $NetBSD: common.c,v 1.23 2009/02/27 04:18:45 msaitoh Exp $
*/ */
#if !defined(lint) && !defined(SCCSID) #if !defined(lint) && !defined(SCCSID)
@ -121,7 +121,7 @@ ed_delete_prev_word(EditLine *el, int c __unused)
*kp++ = *p; *kp++ = *p;
el->el_chared.c_kill.last = kp; el->el_chared.c_kill.last = kp;
c_delbefore(el, el->el_line.cursor - cp); /* delete before dot */ c_delbefore(el, (int)(el->el_line.cursor - cp));/* delete before dot */
el->el_line.cursor = cp; el->el_line.cursor = cp;
if (el->el_line.cursor < el->el_line.buffer) if (el->el_line.cursor < el->el_line.buffer)
el->el_line.cursor = el->el_line.buffer; /* bounds check */ el->el_line.cursor = el->el_line.buffer; /* bounds check */
@ -208,9 +208,6 @@ ed_move_to_end(EditLine *el, int c __unused)
el->el_line.cursor = el->el_line.lastchar; el->el_line.cursor = el->el_line.lastchar;
if (el->el_map.type == MAP_VI) { if (el->el_map.type == MAP_VI) {
#ifdef VI_MOVE
el->el_line.cursor--;
#endif
if (el->el_chared.c_vcmd.action != NOP) { if (el->el_chared.c_vcmd.action != NOP) {
cv_delfini(el); cv_delfini(el);
return (CC_REFRESH); return (CC_REFRESH);

View File

@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $NetBSD: emacs.c,v 1.21 2006/03/06 21:11:56 christos Exp $ * $NetBSD: emacs.c,v 1.22 2009/02/15 21:55:23 christos Exp $
*/ */
#if !defined(lint) && !defined(SCCSID) #if !defined(lint) && !defined(SCCSID)
@ -101,7 +101,7 @@ em_delete_next_word(EditLine *el, int c __unused)
*kp++ = *p; *kp++ = *p;
el->el_chared.c_kill.last = kp; el->el_chared.c_kill.last = kp;
c_delafter(el, cp - el->el_line.cursor); /* delete after dot */ c_delafter(el, (int)(cp - el->el_line.cursor)); /* delete after dot */
if (el->el_line.cursor > el->el_line.lastchar) if (el->el_line.cursor > el->el_line.lastchar)
el->el_line.cursor = el->el_line.lastchar; el->el_line.cursor = el->el_line.lastchar;
/* bounds check */ /* bounds check */
@ -131,7 +131,8 @@ em_yank(EditLine *el, int c __unused)
cp = el->el_line.cursor; cp = el->el_line.cursor;
/* open the space, */ /* open the space, */
c_insert(el, el->el_chared.c_kill.last - el->el_chared.c_kill.buf); c_insert(el,
(int)(el->el_chared.c_kill.last - el->el_chared.c_kill.buf));
/* copy the chars */ /* copy the chars */
for (kp = el->el_chared.c_kill.buf; kp < el->el_chared.c_kill.last; kp++) for (kp = el->el_chared.c_kill.buf; kp < el->el_chared.c_kill.last; kp++)
*cp++ = *kp; *cp++ = *kp;
@ -185,14 +186,14 @@ em_kill_region(EditLine *el, int c __unused)
while (cp < el->el_chared.c_kill.mark) while (cp < el->el_chared.c_kill.mark)
*kp++ = *cp++; /* copy it */ *kp++ = *cp++; /* copy it */
el->el_chared.c_kill.last = kp; el->el_chared.c_kill.last = kp;
c_delafter(el, cp - el->el_line.cursor); c_delafter(el, (int)(cp - el->el_line.cursor));
} else { /* mark is before cursor */ } else { /* mark is before cursor */
cp = el->el_chared.c_kill.mark; cp = el->el_chared.c_kill.mark;
kp = el->el_chared.c_kill.buf; kp = el->el_chared.c_kill.buf;
while (cp < el->el_line.cursor) while (cp < el->el_line.cursor)
*kp++ = *cp++; /* copy it */ *kp++ = *cp++; /* copy it */
el->el_chared.c_kill.last = kp; el->el_chared.c_kill.last = kp;
c_delbefore(el, cp - el->el_chared.c_kill.mark); c_delbefore(el, (int)(cp - el->el_chared.c_kill.mark));
el->el_line.cursor = el->el_chared.c_kill.mark; el->el_line.cursor = el->el_chared.c_kill.mark;
} }
return (CC_REFRESH); return (CC_REFRESH);
@ -446,7 +447,7 @@ em_copy_prev_word(EditLine *el, int c __unused)
cp = c__prev_word(el->el_line.cursor, el->el_line.buffer, cp = c__prev_word(el->el_line.cursor, el->el_line.buffer,
el->el_state.argument, ce__isword); el->el_state.argument, ce__isword);
c_insert(el, oldc - cp); c_insert(el, (int)(oldc - cp));
for (dp = oldc; cp < oldc && dp < el->el_line.lastchar; cp++) for (dp = oldc; cp < oldc && dp < el->el_line.lastchar; cp++)
*dp++ = *cp; *dp++ = *cp;

View File

@ -26,7 +26,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
* *
* $NetBSD: filecomplete.h,v 1.9 2009/12/30 22:37:40 christos Exp $ * $NetBSD: filecomplete.h,v 1.8 2009/02/16 00:15:45 christos Exp $
* $FreeBSD$ * $FreeBSD$
*/ */
#ifndef _FILECOMPLETE_H_ #ifndef _FILECOMPLETE_H_

View File

@ -30,7 +30,7 @@
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* @(#)histedit.h 8.2 (Berkeley) 1/3/94 * @(#)histedit.h 8.2 (Berkeley) 1/3/94
* $NetBSD: histedit.h,v 1.32 2007/06/10 20:20:28 christos Exp $ * $NetBSD: histedit.h,v 1.41 2009/09/07 21:24:33 christos Exp $
* $FreeBSD$ * $FreeBSD$
*/ */

View File

@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $NetBSD: prompt.c,v 1.11 2003/08/07 16:44:32 agc Exp $ * $NetBSD: prompt.c,v 1.14 2009/03/31 17:38:27 christos Exp $
*/ */
#if !defined(lint) && !defined(SCCSID) #if !defined(lint) && !defined(SCCSID)

View File

@ -30,7 +30,7 @@
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* @(#)prompt.h 8.1 (Berkeley) 6/4/93 * @(#)prompt.h 8.1 (Berkeley) 6/4/93
* $NetBSD: prompt.h,v 1.6 2003/08/07 16:44:32 agc Exp $ * $NetBSD: prompt.h,v 1.9 2009/03/31 17:38:27 christos Exp $
* $FreeBSD$ * $FreeBSD$
*/ */
@ -45,8 +45,8 @@
typedef char * (*el_pfunc_t)(EditLine*); typedef char * (*el_pfunc_t)(EditLine*);
typedef struct el_prompt_t { typedef struct el_prompt_t {
el_pfunc_t p_func; /* Function to return the prompt */ el_pfunc_t p_func; /* Function to return the prompt */
coord_t p_pos; /* position in the line after prompt */ coord_t p_pos; /* position in the line after prompt */
char p_ignore; /* character to start/end literal char p_ignore; /* character to start/end literal
*/ */
} el_prompt_t; } el_prompt_t;

View File

@ -26,7 +26,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
* *
* $NetBSD: read.h,v 1.5 2006/08/21 12:45:30 christos Exp $ * $NetBSD: read.h,v 1.6 2008/04/29 06:53:01 martin Exp $
* $FreeBSD$ * $FreeBSD$
*/ */

View File

@ -30,7 +30,7 @@
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* @(#)sys.h 8.1 (Berkeley) 6/4/93 * @(#)sys.h 8.1 (Berkeley) 6/4/93
* $NetBSD: sys.h,v 1.9 2004/01/17 17:57:40 christos Exp $ * $NetBSD: sys.h,v 1.12 2009/08/31 00:05:43 christos Exp $
* $FreeBSD$ * $FreeBSD$
*/ */
@ -70,6 +70,15 @@ typedef void *ioctl_t;
#define REGEX /* Use POSIX.2 regular expression functions */ #define REGEX /* Use POSIX.2 regular expression functions */
#undef REGEXP /* Use UNIX V8 regular expression functions */ #undef REGEXP /* Use UNIX V8 regular expression functions */
#if defined(__sun)
extern int tgetent(char *, const char *);
extern int tgetflag(char *);
extern int tgetnum(char *);
extern int tputs(const char *, int, int (*)(int));
extern char* tgoto(const char*, int, int);
extern char* tgetstr(char*, char**);
#endif
#ifdef notdef #ifdef notdef
# undef REGEX # undef REGEX
# undef REGEXP # undef REGEXP

View File

@ -30,7 +30,7 @@
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* @(#)term.h 8.1 (Berkeley) 6/4/93 * @(#)term.h 8.1 (Berkeley) 6/4/93
* $NetBSD: term.h,v 1.18 2006/11/24 00:01:17 christos Exp $ * $NetBSD: term.h,v 1.20 2009/03/31 17:38:27 christos Exp $
* $FreeBSD$ * $FreeBSD$
*/ */

View File

@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $NetBSD: tty.c,v 1.25 2006/03/18 09:09:41 christos Exp $ * $NetBSD: tty.c,v 1.31 2009/07/22 15:58:09 christos Exp $
*/ */
#if !defined(lint) && !defined(SCCSID) #if !defined(lint) && !defined(SCCSID)
@ -443,13 +443,12 @@ private const ttymodes_t ttymodes[] = {
#define tty_getty(el, td) tcgetattr((el)->el_infd, (td))
#define tty_setty(el, td) tcsetattr((el)->el_infd, TCSADRAIN, (td))
#define tty__gettabs(td) ((((td)->c_oflag & TAB3) == TAB3) ? 0 : 1) #define tty__gettabs(td) ((((td)->c_oflag & TAB3) == TAB3) ? 0 : 1)
#define tty__geteightbit(td) (((td)->c_cflag & CSIZE) == CS8) #define tty__geteightbit(td) (((td)->c_cflag & CSIZE) == CS8)
#define tty__cooked_mode(td) ((td)->c_lflag & ICANON) #define tty__cooked_mode(td) ((td)->c_lflag & ICANON)
private int tty_getty(EditLine *, struct termios *);
private int tty_setty(EditLine *, int, const struct termios *);
private int tty__getcharindex(int); private int tty__getcharindex(int);
private void tty__getchar(struct termios *, unsigned char *); private void tty__getchar(struct termios *, unsigned char *);
private void tty__setchar(struct termios *, unsigned char *); private void tty__setchar(struct termios *, unsigned char *);
@ -458,6 +457,29 @@ private int tty_setup(EditLine *);
#define t_qu t_ts #define t_qu t_ts
/* tty_getty():
* Wrapper for tcgetattr to handle EINTR
*/
private int
tty_getty(EditLine *el, struct termios *t)
{
int rv;
while ((rv = tcgetattr(el->el_infd, t)) == -1 && errno == EINTR)
continue;
return rv;
}
/* tty_setty():
* Wrapper for tcsetattr to handle EINTR
*/
private int
tty_setty(EditLine *el, int action, const struct termios *t)
{
int rv;
while ((rv = tcsetattr(el->el_infd, action, t)) == -1 && errno == EINTR)
continue;
return rv;
}
/* tty_setup(): /* tty_setup():
* Get the tty parameters and initialize the editing state * Get the tty parameters and initialize the editing state
@ -996,7 +1018,7 @@ tty_rawmode(EditLine *el)
if (el->el_tty.t_mode == EX_IO) if (el->el_tty.t_mode == EX_IO)
el->el_tty.t_ex = el->el_tty.t_ts; el->el_tty.t_ex = el->el_tty.t_ts;
if (tty_setty(el, &el->el_tty.t_ed) == -1) { if (tty_setty(el, TCSADRAIN, &el->el_tty.t_ed) == -1) {
#ifdef DEBUG_TTY #ifdef DEBUG_TTY
(void) fprintf(el->el_errfile, "tty_rawmode: tty_setty: %s\n", (void) fprintf(el->el_errfile, "tty_rawmode: tty_setty: %s\n",
strerror(errno)); strerror(errno));
@ -1021,7 +1043,7 @@ tty_cookedmode(EditLine *el)
if (el->el_flags & EDIT_DISABLED) if (el->el_flags & EDIT_DISABLED)
return (0); return (0);
if (tty_setty(el, &el->el_tty.t_ex) == -1) { if (tty_setty(el, TCSADRAIN, &el->el_tty.t_ex) == -1) {
#ifdef DEBUG_TTY #ifdef DEBUG_TTY
(void) fprintf(el->el_errfile, (void) fprintf(el->el_errfile,
"tty_cookedmode: tty_setty: %s\n", "tty_cookedmode: tty_setty: %s\n",
@ -1057,7 +1079,7 @@ tty_quotemode(EditLine *el)
el->el_tty.t_qu.c_lflag &= ~el->el_tty.t_t[QU_IO][MD_LIN].t_clrmask; el->el_tty.t_qu.c_lflag &= ~el->el_tty.t_t[QU_IO][MD_LIN].t_clrmask;
el->el_tty.t_qu.c_lflag |= el->el_tty.t_t[QU_IO][MD_LIN].t_setmask; el->el_tty.t_qu.c_lflag |= el->el_tty.t_t[QU_IO][MD_LIN].t_setmask;
if (tty_setty(el, &el->el_tty.t_qu) == -1) { if (tty_setty(el, TCSADRAIN, &el->el_tty.t_qu) == -1) {
#ifdef DEBUG_TTY #ifdef DEBUG_TTY
(void) fprintf(el->el_errfile, "QuoteModeOn: tty_setty: %s\n", (void) fprintf(el->el_errfile, "QuoteModeOn: tty_setty: %s\n",
strerror(errno)); strerror(errno));
@ -1078,7 +1100,7 @@ tty_noquotemode(EditLine *el)
if (el->el_tty.t_mode != QU_IO) if (el->el_tty.t_mode != QU_IO)
return (0); return (0);
if (tty_setty(el, &el->el_tty.t_ed) == -1) { if (tty_setty(el, TCSADRAIN, &el->el_tty.t_ed) == -1) {
#ifdef DEBUG_TTY #ifdef DEBUG_TTY
(void) fprintf(el->el_errfile, "QuoteModeOff: tty_setty: %s\n", (void) fprintf(el->el_errfile, "QuoteModeOff: tty_setty: %s\n",
strerror(errno)); strerror(errno));
@ -1139,7 +1161,7 @@ tty_stty(EditLine *el, int argc __unused, const char **argv)
if (!argv || !*argv) { if (!argv || !*argv) {
int i = -1; int i = -1;
int len = 0, st = 0, cu; size_t len = 0, st = 0, cu;
for (m = ttymodes; m->m_name; m++) { for (m = ttymodes; m->m_name; m++) {
if (m->m_type != i) { if (m->m_type != i) {
(void) fprintf(el->el_outfile, "%s%s", (void) fprintf(el->el_outfile, "%s%s",
@ -1162,9 +1184,9 @@ tty_stty(EditLine *el, int argc __unused, const char **argv)
cu = strlen(m->m_name) + (x != '\0') + 1; cu = strlen(m->m_name) + (x != '\0') + 1;
if (len + cu >= el->el_term.t_size.h) { if (len + cu >= (size_t)el->el_term.t_size.h) {
(void) fprintf(el->el_outfile, "\n%*s", (void) fprintf(el->el_outfile, "\n%*s",
st, ""); (int)st, "");
len = st + cu; len = st + cu;
} else } else
len += cu; len += cu;
@ -1208,7 +1230,8 @@ tty_stty(EditLine *el, int argc __unused, const char **argv)
int c = ffs((int)m->m_value); int c = ffs((int)m->m_value);
int v = *++p ? parse__escape((const char **) &p) : int v = *++p ? parse__escape((const char **) &p) :
el->el_tty.t_vdisable; el->el_tty.t_vdisable;
assert(c-- != 0); assert(c != 0);
c--;
c = tty__getcharindex(c); c = tty__getcharindex(c);
assert(c != -1); assert(c != -1);
tios->c_cc[c] = v; tios->c_cc[c] = v;
@ -1229,6 +1252,17 @@ tty_stty(EditLine *el, int argc __unused, const char **argv)
break; break;
} }
} }
if (el->el_tty.t_mode == z) {
if (tty_setty(el, TCSADRAIN, tios) == -1) {
#ifdef DEBUG_TTY
(void) fprintf(el->el_errfile,
"tty_stty: tty_setty: %s\n", strerror(errno));
#endif /* DEBUG_TTY */
return (-1);
}
}
return (0); return (0);
} }