Pull up following revision(s) (requested by kre in ticket #102): lib/libedit/Makefile: 1.64-1.65 lib/libedit/editline.3: 1.94-1.96 lib/libedit/editrc.5: 1.33 lib/libedit/el.c: 1.93-1.94 lib/libedit/el.h: 1.42 lib/libedit/literal.c: 1.1-1.3 lib/libedit/literal.h: 1.1-1.2 lib/libedit/prompt.c: 1.27 lib/libedit/read.c: 1.103 lib/libedit/refresh.c: 1.52-1.54 lib/libedit/refresh.h: 1.11 lib/libedit/terminal.c: 1.33 Make the default editrc file be $EDITRC (from env) if set, falling back to $HOME/.editrc otherwise. Better support for this in sh coming. -- Include EDITRC in doc. -- mention the limitation of the literal sequence delimiter. -- - handle literal escape sequence printing. - factor out common code in allocation and freeing of the display. -- - add literal sequence handling. -- remove unused variable -- add literal escape sequence support, patterned after the tcsh ones. -- fix comment -- Fix an obvious, but almost invisible typo (avoid some core dumps). -- Allow wide characters (properly encoded as byte strings according to LC_CTYPE) to be (perhaps part of) the "invisible" characters in a prompt, or the required prompt character which follows the literal sequence (this character must be one with a printing column width >= 1). The literal indicator character (which is just a marker, and not printed anywhere) (the PSlit parameter in sh(1)) can also be a wide char (passed to libedit as a wchar_t, encoded as that by sh(1) or other applications that support this.) Note: this has currently only been tested with everything ascii (C locale). -- Remove workaround for ancient HTML generation code.diff -r1.63 -r1.63.8.1 src/lib/libedit/Makefile
(snj)
--- src/lib/libedit/Makefile 2016/05/24 17:42:54 1.63
+++ src/lib/libedit/Makefile 2017/07/23 14:41:26 1.63.8.1
@@ -1,31 +1,31 @@ | @@ -1,31 +1,31 @@ | |||
1 | # $NetBSD: Makefile,v 1.63 2016/05/24 17:42:54 christos Exp $ | 1 | # $NetBSD: Makefile,v 1.63.8.1 2017/07/23 14:41:26 snj Exp $ | |
2 | # @(#)Makefile 8.1 (Berkeley) 6/4/93 | 2 | # @(#)Makefile 8.1 (Berkeley) 6/4/93 | |
3 | 3 | |||
4 | USE_SHLIBDIR= yes | 4 | USE_SHLIBDIR= yes | |
5 | 5 | |||
6 | WARNS?= 5 | 6 | WARNS?= 5 | |
7 | LIB= edit | 7 | LIB= edit | |
8 | 8 | |||
9 | LIBDPLIBS+= terminfo ${.CURDIR}/../libterminfo | 9 | LIBDPLIBS+= terminfo ${.CURDIR}/../libterminfo | |
10 | 10 | |||
11 | .include "bsd.own.mk" | 11 | .include "bsd.own.mk" | |
12 | 12 | |||
13 | COPTS+= -Wunused-parameter | 13 | COPTS+= -Wunused-parameter | |
14 | CWARNFLAGS.gcc+= -Wconversion | 14 | CWARNFLAGS.gcc+= -Wconversion | |
15 | CWARNFLAGS.clang+= -Wno-cast-qual | 15 | CWARNFLAGS.clang+= -Wno-cast-qual | |
16 | 16 | |||
17 | SRCS = chared.c chartype.c common.c el.c eln.c emacs.c filecomplete.c \ | 17 | SRCS = chared.c chartype.c common.c el.c eln.c emacs.c filecomplete.c \ | |
18 | hist.c history.c historyn.c keymacro.c map.c \ | 18 | hist.c history.c historyn.c keymacro.c literal.c map.c \ | |
19 | parse.c prompt.c read.c readline.c refresh.c search.c sig.c \ | 19 | parse.c prompt.c read.c readline.c refresh.c search.c sig.c \ | |
20 | terminal.c tokenizer.c tokenizern.c tty.c vi.c | 20 | terminal.c tokenizer.c tokenizern.c tty.c vi.c | |
21 | 21 | |||
22 | MAN= editline.3 editrc.5 editline.7 | 22 | MAN= editline.3 editrc.5 editline.7 | |
23 | 23 | |||
24 | MLINKS= \ | 24 | MLINKS= \ | |
25 | editline.3 el_deletestr.3 \ | 25 | editline.3 el_deletestr.3 \ | |
26 | editline.3 el_end.3 \ | 26 | editline.3 el_end.3 \ | |
27 | editline.3 el_get.3 \ | 27 | editline.3 el_get.3 \ | |
28 | editline.3 el_getc.3 \ | 28 | editline.3 el_getc.3 \ | |
29 | editline.3 el_gets.3 \ | 29 | editline.3 el_gets.3 \ | |
30 | editline.3 el_init.3 \ | 30 | editline.3 el_init.3 \ | |
31 | editline.3 el_init_fd.3 \ | 31 | editline.3 el_init_fd.3 \ | |
@@ -123,16 +123,17 @@ help.h: ${ASRC} makelist Makefile | @@ -123,16 +123,17 @@ help.h: ${ASRC} makelist Makefile | |||
123 | 123 | |||
124 | tc1.o: ${LIBEDITDIR}/TEST/tc1.c | 124 | tc1.o: ${LIBEDITDIR}/TEST/tc1.c | |
125 | 125 | |||
126 | tc1: libedit.a tc1.o | 126 | tc1: libedit.a tc1.o | |
127 | ${_MKTARGET_LINK} | 127 | ${_MKTARGET_LINK} | |
128 | ${CC} ${LDFLAGS} ${.ALLSRC} -o ${.TARGET} libedit.a ${LDADD} -ltermlib | 128 | ${CC} ${LDFLAGS} ${.ALLSRC} -o ${.TARGET} libedit.a ${LDADD} -ltermlib | |
129 | 129 | |||
130 | .include <bsd.lib.mk> | 130 | .include <bsd.lib.mk> | |
131 | .include <bsd.subdir.mk> | 131 | .include <bsd.subdir.mk> | |
132 | 132 | |||
133 | # XXX | 133 | # XXX | |
134 | .if defined(HAVE_GCC) | 134 | .if defined(HAVE_GCC) | |
135 | COPTS.editline.c+= -Wno-cast-qual | 135 | COPTS.editline.c+= -Wno-cast-qual | |
136 | COPTS.literal.c+= -Wno-sign-conversion | |||
136 | COPTS.tokenizer.c+= -Wno-cast-qual | 137 | COPTS.tokenizer.c+= -Wno-cast-qual | |
137 | COPTS.tokenizern.c+= -Wno-cast-qual | 138 | COPTS.tokenizern.c+= -Wno-cast-qual | |
138 | .endif | 139 | .endif |
--- src/lib/libedit/editline.3 2017/04/10 15:02:40 1.93
+++ src/lib/libedit/editline.3 2017/07/23 14:41:26 1.93.4.1
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | .\" $NetBSD: editline.3,v 1.93 2017/04/10 15:02:40 abhinav Exp $ | 1 | .\" $NetBSD: editline.3,v 1.93.4.1 2017/07/23 14:41:26 snj Exp $ | |
2 | .\" | 2 | .\" | |
3 | .\" Copyright (c) 1997-2014 The NetBSD Foundation, Inc. | 3 | .\" Copyright (c) 1997-2014 The NetBSD Foundation, Inc. | |
4 | .\" All rights reserved. | 4 | .\" All rights reserved. | |
5 | .\" | 5 | .\" | |
6 | .\" This file was contributed to The NetBSD Foundation by Luke Mewburn. | 6 | .\" This file was contributed to The NetBSD Foundation by Luke Mewburn. | |
7 | .\" | 7 | .\" | |
8 | .\" Redistribution and use in source and binary forms, with or without | 8 | .\" Redistribution and use in source and binary forms, with or without | |
9 | .\" modification, are permitted provided that the following conditions | 9 | .\" modification, are permitted provided that the following conditions | |
10 | .\" are met: | 10 | .\" are met: | |
11 | .\" 1. Redistributions of source code must retain the above copyright | 11 | .\" 1. Redistributions of source code must retain the above copyright | |
12 | .\" notice, this list of conditions and the following disclaimer. | 12 | .\" notice, this list of conditions and the following disclaimer. | |
13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright | |
14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the | |
@@ -16,27 +16,27 @@ | @@ -16,27 +16,27 @@ | |||
16 | .\" | 16 | .\" | |
17 | .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | 17 | .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | |
18 | .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | 18 | .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
19 | .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 19 | .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
20 | .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | 20 | .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | |
21 | .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 21 | .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
22 | .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 22 | .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
23 | .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 23 | .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
24 | .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 24 | .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
25 | .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 25 | .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
26 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 26 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
27 | .\" POSSIBILITY OF SUCH DAMAGE. | 27 | .\" POSSIBILITY OF SUCH DAMAGE. | |
28 | .\" | 28 | .\" | |
29 | .Dd May 22, 2016 | 29 | .Dd June 27, 2017 | |
30 | .Dt EDITLINE 3 | 30 | .Dt EDITLINE 3 | |
31 | .Os | 31 | .Os | |
32 | .Sh NAME | 32 | .Sh NAME | |
33 | .Nm editline , | 33 | .Nm editline , | |
34 | .Nm el_init , | 34 | .Nm el_init , | |
35 | .Nm el_init_fd , | 35 | .Nm el_init_fd , | |
36 | .Nm el_end , | 36 | .Nm el_end , | |
37 | .Nm el_reset , | 37 | .Nm el_reset , | |
38 | .Nm el_gets , | 38 | .Nm el_gets , | |
39 | .Nm el_wgets , | 39 | .Nm el_wgets , | |
40 | .Nm el_getc , | 40 | .Nm el_getc , | |
41 | .Nm el_wgetc , | 41 | .Nm el_wgetc , | |
42 | .Nm el_push , | 42 | .Nm el_push , | |
@@ -348,26 +348,28 @@ which is to return a string that contain | @@ -348,26 +348,28 @@ which is to return a string that contain | |||
348 | Same as | 348 | Same as | |
349 | .Dv EL_PROMPT , | 349 | .Dv EL_PROMPT , | |
350 | but the | 350 | but the | |
351 | .Fa c | 351 | .Fa c | |
352 | argument indicates the start/stop literal prompt character. | 352 | argument indicates the start/stop literal prompt character. | |
353 | .Pp | 353 | .Pp | |
354 | If a start/stop literal character is found in the prompt, the | 354 | If a start/stop literal character is found in the prompt, the | |
355 | character itself | 355 | character itself | |
356 | is not printed, but characters after it are printed directly to the | 356 | is not printed, but characters after it are printed directly to the | |
357 | terminal without affecting the state of the current line. | 357 | terminal without affecting the state of the current line. | |
358 | A subsequent second start/stop literal character ends this behavior. | 358 | A subsequent second start/stop literal character ends this behavior. | |
359 | This is typically used to embed literal escape sequences that change the | 359 | This is typically used to embed literal escape sequences that change the | |
360 | color/style of the terminal in the prompt. | 360 | color/style of the terminal in the prompt. | |
361 | Note that the literal escape character cannot be the last character in the | |||
362 | prompt, as the escape sequence is attached to the next character in the prompt. | |||
361 | .Dv 0 | 363 | .Dv 0 | |
362 | unsets it. | 364 | unsets it. | |
363 | .It Dv EL_REFRESH | 365 | .It Dv EL_REFRESH | |
364 | Re-display the current line on the next terminal line. | 366 | Re-display the current line on the next terminal line. | |
365 | .It Dv EL_RPROMPT , Fa "char *(*f)(EditLine *)" | 367 | .It Dv EL_RPROMPT , Fa "char *(*f)(EditLine *)" | |
366 | Define right side prompt printing function as | 368 | Define right side prompt printing function as | |
367 | .Fa f , | 369 | .Fa f , | |
368 | which is to return a string that contains the prompt. | 370 | which is to return a string that contains the prompt. | |
369 | .It Dv EL_RPROMPT_ESC , Fa "char *(*f)(EditLine *)" , Fa "char c" | 371 | .It Dv EL_RPROMPT_ESC , Fa "char *(*f)(EditLine *)" , Fa "char c" | |
370 | Define the right prompt printing function but with a literal escape character. | 372 | Define the right prompt printing function but with a literal escape character. | |
371 | .It Dv EL_TERMINAL , Fa "const char *type" | 373 | .It Dv EL_TERMINAL , Fa "const char *type" | |
372 | Define terminal type of the tty to be | 374 | Define terminal type of the tty to be | |
373 | .Fa type , | 375 | .Fa type , | |
@@ -657,26 +659,28 @@ or | @@ -657,26 +659,28 @@ or | |||
657 | .It Fn el_source | 659 | .It Fn el_source | |
658 | Initialize | 660 | Initialize | |
659 | .Nm | 661 | .Nm | |
660 | by reading the contents of | 662 | by reading the contents of | |
661 | .Fa file . | 663 | .Fa file . | |
662 | .Fn el_parse | 664 | .Fn el_parse | |
663 | is called for each line in | 665 | is called for each line in | |
664 | .Fa file . | 666 | .Fa file . | |
665 | If | 667 | If | |
666 | .Fa file | 668 | .Fa file | |
667 | is | 669 | is | |
668 | .Dv NULL , | 670 | .Dv NULL , | |
669 | try | 671 | try | |
672 | .Pa $EDITRC | |||
673 | and if that is not set | |||
670 | .Pa $HOME/.editrc . | 674 | .Pa $HOME/.editrc . | |
671 | Refer to | 675 | Refer to | |
672 | .Xr editrc 5 | 676 | .Xr editrc 5 | |
673 | for details on the format of | 677 | for details on the format of | |
674 | .Fa file . | 678 | .Fa file . | |
675 | .Fn el_source | 679 | .Fn el_source | |
676 | returns 0 on success and \-1 on error. | 680 | returns 0 on success and \-1 on error. | |
677 | .It Fn el_resize | 681 | .It Fn el_resize | |
678 | Must be called if the terminal size changes. | 682 | Must be called if the terminal size changes. | |
679 | If | 683 | If | |
680 | .Dv EL_SIGNAL | 684 | .Dv EL_SIGNAL | |
681 | has been set with | 685 | has been set with | |
682 | .Fn el_set , | 686 | .Fn el_set , | |
@@ -846,27 +850,27 @@ into the history. | @@ -846,27 +850,27 @@ into the history. | |||
846 | Retrieve the current setting if adjacent identical elements should | 850 | Retrieve the current setting if adjacent identical elements should | |
847 | be entered into the history. | 851 | be entered into the history. | |
848 | .It Dv H_DEL , Fa "int e" | 852 | .It Dv H_DEL , Fa "int e" | |
849 | Delete the event numbered | 853 | Delete the event numbered | |
850 | .Fa e . | 854 | .Fa e . | |
851 | This function is only provided for | 855 | This function is only provided for | |
852 | .Xr readline 3 | 856 | .Xr readline 3 | |
853 | compatibility. | 857 | compatibility. | |
854 | The caller is responsible for free'ing the string in the returned | 858 | The caller is responsible for free'ing the string in the returned | |
855 | .Fa HistEvent . | 859 | .Fa HistEvent . | |
856 | .El | 860 | .El | |
857 | .Pp | 861 | .Pp | |
858 | .Fn history | 862 | .Fn history | |
859 | returns \*[Gt]= 0 if the operation | 863 | returns >= 0 if the operation | |
860 | .Fa op | 864 | .Fa op | |
861 | succeeds. | 865 | succeeds. | |
862 | Otherwise, \-1 is returned and | 866 | Otherwise, \-1 is returned and | |
863 | .Fa ev | 867 | .Fa ev | |
864 | is updated to contain more details about the error. | 868 | is updated to contain more details about the error. | |
865 | .El | 869 | .El | |
866 | .Sh TOKENIZATION FUNCTIONS | 870 | .Sh TOKENIZATION FUNCTIONS | |
867 | The tokenization functions use a common data structure, | 871 | The tokenization functions use a common data structure, | |
868 | .Fa Tokenizer , | 872 | .Fa Tokenizer , | |
869 | which is created by | 873 | which is created by | |
870 | .Fn tok_init | 874 | .Fn tok_init | |
871 | and freed by | 875 | and freed by | |
872 | .Fn tok_end . | 876 | .Fn tok_end . |
--- src/lib/libedit/editrc.5 2016/05/22 23:54:20 1.32
+++ src/lib/libedit/editrc.5 2017/07/23 14:41:26 1.32.8.1
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | .\" $NetBSD: editrc.5,v 1.32 2016/05/22 23:54:20 christos Exp $ | 1 | .\" $NetBSD: editrc.5,v 1.32.8.1 2017/07/23 14:41:26 snj Exp $ | |
2 | .\" | 2 | .\" | |
3 | .\" Copyright (c) 1997-2000 The NetBSD Foundation, Inc. | 3 | .\" Copyright (c) 1997-2000 The NetBSD Foundation, Inc. | |
4 | .\" All rights reserved. | 4 | .\" All rights reserved. | |
5 | .\" | 5 | .\" | |
6 | .\" This file was contributed to The NetBSD Foundation by Luke Mewburn. | 6 | .\" This file was contributed to The NetBSD Foundation by Luke Mewburn. | |
7 | .\" | 7 | .\" | |
8 | .\" Redistribution and use in source and binary forms, with or without | 8 | .\" Redistribution and use in source and binary forms, with or without | |
9 | .\" modification, are permitted provided that the following conditions | 9 | .\" modification, are permitted provided that the following conditions | |
10 | .\" are met: | 10 | .\" are met: | |
11 | .\" 1. Redistributions of source code must retain the above copyright | 11 | .\" 1. Redistributions of source code must retain the above copyright | |
12 | .\" notice, this list of conditions and the following disclaimer. | 12 | .\" notice, this list of conditions and the following disclaimer. | |
13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright | |
14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the | |
@@ -283,30 +283,38 @@ in the chosen set. | @@ -283,30 +283,38 @@ in the chosen set. | |||
283 | .Pp | 283 | .Pp | |
284 | .Ic Setty | 284 | .Ic Setty | |
285 | can also be used to set tty characters to particular values using | 285 | can also be used to set tty characters to particular values using | |
286 | .Ar char=value . | 286 | .Ar char=value . | |
287 | If | 287 | If | |
288 | .Ar value | 288 | .Ar value | |
289 | is empty | 289 | is empty | |
290 | then the character is set to | 290 | then the character is set to | |
291 | .Dv _POSIX_VDISABLE . | 291 | .Dv _POSIX_VDISABLE . | |
292 | .It Ic telltc | 292 | .It Ic telltc | |
293 | List the values of all the terminal capabilities (see | 293 | List the values of all the terminal capabilities (see | |
294 | .Xr termcap 5 ) . | 294 | .Xr termcap 5 ) . | |
295 | .El | 295 | .El | |
296 | .Sh ENVIRONMENT | |||
297 | .Bl -tag -width "~/.editrcXXX" | |||
298 | .It Ev EDITRC | |||
299 | Names the default configuration file for the | |||
300 | .Xr editline 3 | |||
301 | library. | |||
302 | .El | |||
296 | .Sh FILES | 303 | .Sh FILES | |
297 | .Bl -tag -width "~/.editrcXXX" | 304 | .Bl -tag -width "~/.editrcXXX" | |
298 | .It Pa ~/.editrc | 305 | .It Pa ~/.editrc | |
299 | User configuration file for the | 306 | Last resort, if no other file is specified, | |
307 | user configuration file for the | |||
300 | .Xr editline 3 | 308 | .Xr editline 3 | |
301 | library. | 309 | library. | |
302 | .El | 310 | .El | |
303 | .Sh SEE ALSO | 311 | .Sh SEE ALSO | |
304 | .Xr editline 3 , | 312 | .Xr editline 3 , | |
305 | .Xr regex 3 , | 313 | .Xr regex 3 , | |
306 | .Xr termcap 5 , | 314 | .Xr termcap 5 , | |
307 | .Xr editline 7 | 315 | .Xr editline 7 | |
308 | .Sh AUTHORS | 316 | .Sh AUTHORS | |
309 | .An -nosplit | 317 | .An -nosplit | |
310 | The | 318 | The | |
311 | .Nm editline | 319 | .Nm editline | |
312 | library was written by | 320 | library was written by |
--- src/lib/libedit/terminal.c 2016/05/09 21:46:56 1.32
+++ src/lib/libedit/terminal.c 2017/07/23 14:41:26 1.32.8.1
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: terminal.c,v 1.32 2016/05/09 21:46:56 christos Exp $ */ | 1 | /* $NetBSD: terminal.c,v 1.32.8.1 2017/07/23 14:41:26 snj Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1992, 1993 | 4 | * Copyright (c) 1992, 1993 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to Berkeley by | 7 | * This code is derived from software contributed to Berkeley by | |
8 | * Christos Zoulas of Cornell University. | 8 | * Christos Zoulas of Cornell University. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -27,27 +27,27 @@ | @@ -27,27 +27,27 @@ | |||
27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
32 | * SUCH DAMAGE. | 32 | * SUCH DAMAGE. | |
33 | */ | 33 | */ | |
34 | 34 | |||
35 | #include "config.h" | 35 | #include "config.h" | |
36 | #if !defined(lint) && !defined(SCCSID) | 36 | #if !defined(lint) && !defined(SCCSID) | |
37 | #if 0 | 37 | #if 0 | |
38 | static char sccsid[] = "@(#)term.c 8.2 (Berkeley) 4/30/95"; | 38 | static char sccsid[] = "@(#)term.c 8.2 (Berkeley) 4/30/95"; | |
39 | #else | 39 | #else | |
40 | __RCSID("$NetBSD: terminal.c,v 1.32 2016/05/09 21:46:56 christos Exp $"); | 40 | __RCSID("$NetBSD: terminal.c,v 1.32.8.1 2017/07/23 14:41:26 snj Exp $"); | |
41 | #endif | 41 | #endif | |
42 | #endif /* not lint && not SCCSID */ | 42 | #endif /* not lint && not SCCSID */ | |
43 | 43 | |||
44 | /* | 44 | /* | |
45 | * terminal.c: Editor/termcap-curses interface | 45 | * terminal.c: Editor/termcap-curses interface | |
46 | * We have to declare a static variable here, since the | 46 | * We have to declare a static variable here, since the | |
47 | * termcap putchar routine does not take an argument! | 47 | * termcap putchar routine does not take an argument! | |
48 | */ | 48 | */ | |
49 | #include <sys/types.h> | 49 | #include <sys/types.h> | |
50 | #include <sys/ioctl.h> | 50 | #include <sys/ioctl.h> | |
51 | #include <limits.h> | 51 | #include <limits.h> | |
52 | #include <signal.h> | 52 | #include <signal.h> | |
53 | #include <stdio.h> | 53 | #include <stdio.h> | |
@@ -409,96 +409,93 @@ terminal_rebuffer_display(EditLine *el) | @@ -409,96 +409,93 @@ terminal_rebuffer_display(EditLine *el) | |||
409 | { | 409 | { | |
410 | coord_t *c = &el->el_terminal.t_size; | 410 | coord_t *c = &el->el_terminal.t_size; | |
411 | 411 | |||
412 | terminal_free_display(el); | 412 | terminal_free_display(el); | |
413 | 413 | |||
414 | c->h = Val(T_co); | 414 | c->h = Val(T_co); | |
415 | c->v = Val(T_li); | 415 | c->v = Val(T_li); | |
416 | 416 | |||
417 | if (terminal_alloc_display(el) == -1) | 417 | if (terminal_alloc_display(el) == -1) | |
418 | return -1; | 418 | return -1; | |
419 | return 0; | 419 | return 0; | |
420 | } | 420 | } | |
421 | 421 | |||
422 | 422 | static wchar_t ** | ||
423 | /* terminal_alloc_display(): | 423 | terminal_alloc_buffer(EditLine *el) | |
424 | * Allocate a new display. | |||
425 | */ | |||
426 | static int | |||
427 | terminal_alloc_display(EditLine *el) | |||
428 | { | 424 | { | |
429 | int i; | 425 | wint_t **b; | |
430 | wchar_t **b; | |||
431 | coord_t *c = &el->el_terminal.t_size; | 426 | coord_t *c = &el->el_terminal.t_size; | |
427 | int i; | |||
432 | 428 | |||
433 | b = el_malloc(sizeof(*b) * (size_t)(c->v + 1)); | 429 | b = el_malloc(sizeof(*b) * (size_t)(c->v + 1)); | |
434 | if (b == NULL) | 430 | if (b == NULL) | |
435 | goto done; | 431 | return NULL; | |
436 | for (i = 0; i < c->v; i++) { | 432 | for (i = 0; i < c->v; i++) { | |
437 | b[i] = el_malloc(sizeof(**b) * (size_t)(c->h + 1)); | 433 | b[i] = el_malloc(sizeof(**b) * (size_t)(c->h + 1)); | |
438 | if (b[i] == NULL) { | 434 | if (b[i] == NULL) { | |
439 | while (--i >= 0) | 435 | while (--i >= 0) | |
440 | el_free(b[i]); | 436 | el_free(b[i]); | |
441 | el_free(b); | 437 | el_free(b); | |
442 | goto done; | 438 | return NULL; | |
443 | } | 439 | } | |
444 | } | 440 | } | |
445 | b[c->v] = NULL; | 441 | b[c->v] = NULL; | |
446 | el->el_display = b; | 442 | return b; | |
443 | } | |||
447 | 444 | |||
448 | b = el_malloc(sizeof(*b) * (size_t)(c->v + 1)); | 445 | static void | |
449 | if (b == NULL) | 446 | terminal_free_buffer(wint_t ***bp) | |
447 | { | |||
448 | wint_t **b; | |||
449 | wint_t **bufp; | |||
450 | ||||
451 | if (*bp == NULL) | |||
452 | return; | |||
453 | ||||
454 | b = *bp; | |||
455 | *bp = NULL; | |||
456 | ||||
457 | for (bufp = b; *bufp != NULL; bufp++) | |||
458 | el_free(*bufp); | |||
459 | el_free(b); | |||
460 | } | |||
461 | ||||
462 | /* terminal_alloc_display(): | |||
463 | * Allocate a new display. | |||
464 | */ | |||
465 | static int | |||
466 | terminal_alloc_display(EditLine *el) | |||
467 | { | |||
468 | el->el_display = terminal_alloc_buffer(el); | |||
469 | if (el->el_display == NULL) | |||
470 | goto done; | |||
471 | el->el_vdisplay = terminal_alloc_buffer(el); | |||
472 | if (el->el_vdisplay == NULL) | |||
450 | goto done; | 473 | goto done; | |
451 | for (i = 0; i < c->v; i++) { | |||
452 | b[i] = el_malloc(sizeof(**b) * (size_t)(c->h + 1)); | |||
453 | if (b[i] == NULL) { | |||
454 | while (--i >= 0) | |||
455 | el_free(b[i]); | |||
456 | el_free(b); | |||
457 | goto done; | |||
458 | } | |||
459 | } | |||
460 | b[c->v] = NULL; | |||
461 | el->el_vdisplay = b; | |||
462 | return 0; | 474 | return 0; | |
463 | done: | 475 | done: | |
464 | terminal_free_display(el); | 476 | terminal_free_display(el); | |
465 | return -1; | 477 | return -1; | |
466 | } | 478 | } | |
467 | 479 | |||
468 | 480 | |||
469 | /* terminal_free_display(): | 481 | /* terminal_free_display(): | |
470 | * Free the display buffers | 482 | * Free the display buffers | |
471 | */ | 483 | */ | |
472 | static void | 484 | static void | |
473 | terminal_free_display(EditLine *el) | 485 | terminal_free_display(EditLine *el) | |
474 | { | 486 | { | |
475 | wchar_t **b; | 487 | terminal_free_buffer(&el->el_display); | |
476 | wchar_t **bufp; | 488 | terminal_free_buffer(&el->el_vdisplay); | |
477 | ||||
478 | b = el->el_display; | |||
479 | el->el_display = NULL; | |||
480 | if (b != NULL) { | |||
481 | for (bufp = b; *bufp != NULL; bufp++) | |||
482 | el_free(*bufp); | |||
483 | el_free(b); | |||
484 | } | |||
485 | b = el->el_vdisplay; | |||
486 | el->el_vdisplay = NULL; | |||
487 | if (b != NULL) { | |||
488 | for (bufp = b; *bufp != NULL; bufp++) | |||
489 | el_free(*bufp); | |||
490 | el_free(b); | |||
491 | } | |||
492 | } | 489 | } | |
493 | 490 | |||
494 | 491 | |||
495 | /* terminal_move_to_line(): | 492 | /* terminal_move_to_line(): | |
496 | * move to line <where> (first line == 0) | 493 | * move to line <where> (first line == 0) | |
497 | * as efficiently as possible | 494 | * as efficiently as possible | |
498 | */ | 495 | */ | |
499 | libedit_private void | 496 | libedit_private void | |
500 | terminal_move_to_line(EditLine *el, int where) | 497 | terminal_move_to_line(EditLine *el, int where) | |
501 | { | 498 | { | |
502 | int del; | 499 | int del; | |
503 | 500 | |||
504 | if (where == el->el_cursor.v) | 501 | if (where == el->el_cursor.v) | |
@@ -1244,26 +1241,28 @@ terminal_tputs(EditLine *el, const char | @@ -1244,26 +1241,28 @@ terminal_tputs(EditLine *el, const char | |||
1244 | #endif | 1241 | #endif | |
1245 | } | 1242 | } | |
1246 | 1243 | |||
1247 | /* terminal__putc(): | 1244 | /* terminal__putc(): | |
1248 | * Add a character | 1245 | * Add a character | |
1249 | */ | 1246 | */ | |
1250 | libedit_private int | 1247 | libedit_private int | |
1251 | terminal__putc(EditLine *el, wint_t c) | 1248 | terminal__putc(EditLine *el, wint_t c) | |
1252 | { | 1249 | { | |
1253 | char buf[MB_LEN_MAX +1]; | 1250 | char buf[MB_LEN_MAX +1]; | |
1254 | ssize_t i; | 1251 | ssize_t i; | |
1255 | if (c == (wint_t)MB_FILL_CHAR) | 1252 | if (c == (wint_t)MB_FILL_CHAR) | |
1256 | return 0; | 1253 | return 0; | |
1254 | if (c & EL_LITERAL) | |||
1255 | return fputs(literal_get(el, c), el->el_outfile); | |||
1257 | i = ct_encode_char(buf, (size_t)MB_LEN_MAX, c); | 1256 | i = ct_encode_char(buf, (size_t)MB_LEN_MAX, c); | |
1258 | if (i <= 0) | 1257 | if (i <= 0) | |
1259 | return (int)i; | 1258 | return (int)i; | |
1260 | buf[i] = '\0'; | 1259 | buf[i] = '\0'; | |
1261 | return fputs(buf, el->el_outfile); | 1260 | return fputs(buf, el->el_outfile); | |
1262 | } | 1261 | } | |
1263 | 1262 | |||
1264 | /* terminal__flush(): | 1263 | /* terminal__flush(): | |
1265 | * Flush output | 1264 | * Flush output | |
1266 | */ | 1265 | */ | |
1267 | libedit_private void | 1266 | libedit_private void | |
1268 | terminal__flush(EditLine *el) | 1267 | terminal__flush(EditLine *el) | |
1269 | { | 1268 | { |
--- src/lib/libedit/el.c 2016/05/22 19:44:26 1.92
+++ src/lib/libedit/el.c 2017/07/23 14:41:26 1.92.8.1
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: el.c,v 1.92 2016/05/22 19:44:26 christos Exp $ */ | 1 | /* $NetBSD: el.c,v 1.92.8.1 2017/07/23 14:41:26 snj Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1992, 1993 | 4 | * Copyright (c) 1992, 1993 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to Berkeley by | 7 | * This code is derived from software contributed to Berkeley by | |
8 | * Christos Zoulas of Cornell University. | 8 | * Christos Zoulas of Cornell University. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -27,27 +27,27 @@ | @@ -27,27 +27,27 @@ | |||
27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
32 | * SUCH DAMAGE. | 32 | * SUCH DAMAGE. | |
33 | */ | 33 | */ | |
34 | 34 | |||
35 | #include "config.h" | 35 | #include "config.h" | |
36 | #if !defined(lint) && !defined(SCCSID) | 36 | #if !defined(lint) && !defined(SCCSID) | |
37 | #if 0 | 37 | #if 0 | |
38 | static char sccsid[] = "@(#)el.c 8.2 (Berkeley) 1/3/94"; | 38 | static char sccsid[] = "@(#)el.c 8.2 (Berkeley) 1/3/94"; | |
39 | #else | 39 | #else | |
40 | __RCSID("$NetBSD: el.c,v 1.92 2016/05/22 19:44:26 christos Exp $"); | 40 | __RCSID("$NetBSD: el.c,v 1.92.8.1 2017/07/23 14:41:26 snj Exp $"); | |
41 | #endif | 41 | #endif | |
42 | #endif /* not lint && not SCCSID */ | 42 | #endif /* not lint && not SCCSID */ | |
43 | 43 | |||
44 | /* | 44 | /* | |
45 | * el.c: EditLine interface functions | 45 | * el.c: EditLine interface functions | |
46 | */ | 46 | */ | |
47 | #include <sys/types.h> | 47 | #include <sys/types.h> | |
48 | #include <sys/param.h> | 48 | #include <sys/param.h> | |
49 | #include <ctype.h> | 49 | #include <ctype.h> | |
50 | #include <langinfo.h> | 50 | #include <langinfo.h> | |
51 | #include <locale.h> | 51 | #include <locale.h> | |
52 | #include <stdarg.h> | 52 | #include <stdarg.h> | |
53 | #include <stdlib.h> | 53 | #include <stdlib.h> | |
@@ -105,26 +105,27 @@ el_init_fd(const char *prog, FILE *fin, | @@ -105,26 +105,27 @@ el_init_fd(const char *prog, FILE *fin, | |||
105 | el_free(el->el_prog); | 105 | el_free(el->el_prog); | |
106 | el_free(el); | 106 | el_free(el); | |
107 | return NULL; | 107 | return NULL; | |
108 | } | 108 | } | |
109 | (void) keymacro_init(el); | 109 | (void) keymacro_init(el); | |
110 | (void) map_init(el); | 110 | (void) map_init(el); | |
111 | if (tty_init(el) == -1) | 111 | if (tty_init(el) == -1) | |
112 | el->el_flags |= NO_TTY; | 112 | el->el_flags |= NO_TTY; | |
113 | (void) ch_init(el); | 113 | (void) ch_init(el); | |
114 | (void) search_init(el); | 114 | (void) search_init(el); | |
115 | (void) hist_init(el); | 115 | (void) hist_init(el); | |
116 | (void) prompt_init(el); | 116 | (void) prompt_init(el); | |
117 | (void) sig_init(el); | 117 | (void) sig_init(el); | |
118 | (void) literal_init(el); | |||
118 | if (read_init(el) == -1) { | 119 | if (read_init(el) == -1) { | |
119 | el_end(el); | 120 | el_end(el); | |
120 | return NULL; | 121 | return NULL; | |
121 | } | 122 | } | |
122 | return el; | 123 | return el; | |
123 | } | 124 | } | |
124 | 125 | |||
125 | 126 | |||
126 | /* el_end(): | 127 | /* el_end(): | |
127 | * Clean up. | 128 | * Clean up. | |
128 | */ | 129 | */ | |
129 | void | 130 | void | |
130 | el_end(EditLine *el) | 131 | el_end(EditLine *el) | |
@@ -136,26 +137,27 @@ el_end(EditLine *el) | @@ -136,26 +137,27 @@ el_end(EditLine *el) | |||
136 | el_reset(el); | 137 | el_reset(el); | |
137 | 138 | |||
138 | terminal_end(el); | 139 | terminal_end(el); | |
139 | keymacro_end(el); | 140 | keymacro_end(el); | |
140 | map_end(el); | 141 | map_end(el); | |
141 | if (!(el->el_flags & NO_TTY)) | 142 | if (!(el->el_flags & NO_TTY)) | |
142 | tty_end(el); | 143 | tty_end(el); | |
143 | ch_end(el); | 144 | ch_end(el); | |
144 | read_end(el->el_read); | 145 | read_end(el->el_read); | |
145 | search_end(el); | 146 | search_end(el); | |
146 | hist_end(el); | 147 | hist_end(el); | |
147 | prompt_end(el); | 148 | prompt_end(el); | |
148 | sig_end(el); | 149 | sig_end(el); | |
150 | literal_end(el); | |||
149 | 151 | |||
150 | el_free(el->el_prog); | 152 | el_free(el->el_prog); | |
151 | el_free(el->el_visual.cbuff); | 153 | el_free(el->el_visual.cbuff); | |
152 | el_free(el->el_visual.wbuff); | 154 | el_free(el->el_visual.wbuff); | |
153 | el_free(el->el_scratch.cbuff); | 155 | el_free(el->el_scratch.cbuff); | |
154 | el_free(el->el_scratch.wbuff); | 156 | el_free(el->el_scratch.wbuff); | |
155 | el_free(el->el_lgcyconv.cbuff); | 157 | el_free(el->el_lgcyconv.cbuff); | |
156 | el_free(el->el_lgcyconv.wbuff); | 158 | el_free(el->el_lgcyconv.wbuff); | |
157 | el_free(el); | 159 | el_free(el); | |
158 | } | 160 | } | |
159 | 161 | |||
160 | 162 | |||
161 | /* el_reset(): | 163 | /* el_reset(): | |
@@ -514,47 +516,54 @@ int | @@ -514,47 +516,54 @@ int | |||
514 | el_source(EditLine *el, const char *fname) | 516 | el_source(EditLine *el, const char *fname) | |
515 | { | 517 | { | |
516 | FILE *fp; | 518 | FILE *fp; | |
517 | size_t len; | 519 | size_t len; | |
518 | ssize_t slen; | 520 | ssize_t slen; | |
519 | char *ptr; | 521 | char *ptr; | |
520 | char *path = NULL; | 522 | char *path = NULL; | |
521 | const wchar_t *dptr; | 523 | const wchar_t *dptr; | |
522 | int error = 0; | 524 | int error = 0; | |
523 | 525 | |||
524 | fp = NULL; | 526 | fp = NULL; | |
525 | if (fname == NULL) { | 527 | if (fname == NULL) { | |
526 | #ifdef HAVE_ISSETUGID | 528 | #ifdef HAVE_ISSETUGID | |
527 | static const char elpath[] = "/.editrc"; | |||
528 | size_t plen = sizeof(elpath); | |||
529 | ||||
530 | if (issetugid()) | 529 | if (issetugid()) | |
531 | return -1; | 530 | return -1; | |
532 | if ((ptr = getenv("HOME")) == NULL) | 531 | ||
533 | return -1; | 532 | if ((fname = getenv("EDITRC")) == NULL) { | |
534 | plen += strlen(ptr); | 533 | static const char elpath[] = "/.editrc"; | |
535 | if ((path = el_malloc(plen * sizeof(*path))) == NULL) | 534 | size_t plen = sizeof(elpath); | |
536 | return -1; | 535 | ||
537 | (void)snprintf(path, plen, "%s%s", ptr, elpath); | 536 | if ((ptr = getenv("HOME")) == NULL) | |
538 | fname = path; | 537 | return -1; | |
538 | plen += strlen(ptr); | |||
539 | if ((path = el_malloc(plen * sizeof(*path))) == NULL) | |||
540 | return -1; | |||
541 | (void)snprintf(path, plen, "%s%s", ptr, | |||
542 | elpath + (*ptr == '\0')); | |||
543 | fname = path; | |||
544 | } | |||
539 | #else | 545 | #else | |
540 | /* | 546 | /* | |
541 | * If issetugid() is missing, always return an error, in order | 547 | * If issetugid() is missing, always return an error, in order | |
542 | * to keep from inadvertently opening up the user to a security | 548 | * to keep from inadvertently opening up the user to a security | |
543 | * hole. | 549 | * hole. | |
544 | */ | 550 | */ | |
545 | return -1; | 551 | return -1; | |
546 | #endif | 552 | #endif | |
547 | } | 553 | } | |
554 | if (fname[0] == '\0') | |||
555 | return -1; | |||
556 | ||||
548 | if (fp == NULL) | 557 | if (fp == NULL) | |
549 | fp = fopen(fname, "r"); | 558 | fp = fopen(fname, "r"); | |
550 | if (fp == NULL) { | 559 | if (fp == NULL) { | |
551 | el_free(path); | 560 | el_free(path); | |
552 | return -1; | 561 | return -1; | |
553 | } | 562 | } | |
554 | 563 | |||
555 | ptr = NULL; | 564 | ptr = NULL; | |
556 | len = 0; | 565 | len = 0; | |
557 | while ((slen = getline(&ptr, &len, fp)) != -1) { | 566 | while ((slen = getline(&ptr, &len, fp)) != -1) { | |
558 | if (*ptr == '\n') | 567 | if (*ptr == '\n') | |
559 | continue; /* Empty line. */ | 568 | continue; /* Empty line. */ | |
560 | if (slen > 0 && ptr[--slen] == '\n') | 569 | if (slen > 0 && ptr[--slen] == '\n') |
--- src/lib/libedit/el.h 2016/05/24 15:00:45 1.41
+++ src/lib/libedit/el.h 2017/07/23 14:41:26 1.41.8.1
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: el.h,v 1.41 2016/05/24 15:00:45 christos Exp $ */ | 1 | /* $NetBSD: el.h,v 1.41.8.1 2017/07/23 14:41:26 snj Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1992, 1993 | 4 | * Copyright (c) 1992, 1993 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to Berkeley by | 7 | * This code is derived from software contributed to Berkeley by | |
8 | * Christos Zoulas of Cornell University. | 8 | * Christos Zoulas of Cornell University. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -84,57 +84,59 @@ typedef struct el_state_t { | @@ -84,57 +84,59 @@ typedef struct el_state_t { | |||
84 | el_action_t thiscmd; /* this command */ | 84 | el_action_t thiscmd; /* this command */ | |
85 | wchar_t thisch; /* char that generated it */ | 85 | wchar_t thisch; /* char that generated it */ | |
86 | } el_state_t; | 86 | } el_state_t; | |
87 | 87 | |||
88 | /* | 88 | /* | |
89 | * Until we come up with something better... | 89 | * Until we come up with something better... | |
90 | */ | 90 | */ | |
91 | #define el_malloc(a) malloc(a) | 91 | #define el_malloc(a) malloc(a) | |
92 | #define el_realloc(a,b) realloc(a, b) | 92 | #define el_realloc(a,b) realloc(a, b) | |
93 | #define el_free(a) free(a) | 93 | #define el_free(a) free(a) | |
94 | 94 | |||
95 | #include "tty.h" | 95 | #include "tty.h" | |
96 | #include "prompt.h" | 96 | #include "prompt.h" | |
97 | #include "literal.h" | |||
97 | #include "keymacro.h" | 98 | #include "keymacro.h" | |
98 | #include "terminal.h" | 99 | #include "terminal.h" | |
99 | #include "refresh.h" | 100 | #include "refresh.h" | |
100 | #include "chared.h" | 101 | #include "chared.h" | |
101 | #include "search.h" | 102 | #include "search.h" | |
102 | #include "hist.h" | 103 | #include "hist.h" | |
103 | #include "map.h" | 104 | #include "map.h" | |
104 | #include "sig.h" | 105 | #include "sig.h" | |
105 | 106 | |||
106 | struct el_read_t; | 107 | struct el_read_t; | |
107 | 108 | |||
108 | struct editline { | 109 | struct editline { | |
109 | wchar_t *el_prog; /* the program name */ | 110 | wchar_t *el_prog; /* the program name */ | |
110 | FILE *el_infile; /* Stdio stuff */ | 111 | FILE *el_infile; /* Stdio stuff */ | |
111 | FILE *el_outfile; /* Stdio stuff */ | 112 | FILE *el_outfile; /* Stdio stuff */ | |
112 | FILE *el_errfile; /* Stdio stuff */ | 113 | FILE *el_errfile; /* Stdio stuff */ | |
113 | int el_infd; /* Input file descriptor */ | 114 | int el_infd; /* Input file descriptor */ | |
114 | int el_outfd; /* Output file descriptor */ | 115 | int el_outfd; /* Output file descriptor */ | |
115 | int el_errfd; /* Error file descriptor */ | 116 | int el_errfd; /* Error file descriptor */ | |
116 | int el_flags; /* Various flags. */ | 117 | int el_flags; /* Various flags. */ | |
117 | coord_t el_cursor; /* Cursor location */ | 118 | coord_t el_cursor; /* Cursor location */ | |
118 | wchar_t **el_display; /* Real screen image = what is there */ | 119 | wint_t **el_display; /* Real screen image = what is there */ | |
119 | wchar_t **el_vdisplay; /* Virtual screen image = what we see */ | 120 | wint_t **el_vdisplay; /* Virtual screen image = what we see */ | |
120 | void *el_data; /* Client data */ | 121 | void *el_data; /* Client data */ | |
121 | el_line_t el_line; /* The current line information */ | 122 | el_line_t el_line; /* The current line information */ | |
122 | el_state_t el_state; /* Current editor state */ | 123 | el_state_t el_state; /* Current editor state */ | |
123 | el_terminal_t el_terminal; /* Terminal dependent stuff */ | 124 | el_terminal_t el_terminal; /* Terminal dependent stuff */ | |
124 | el_tty_t el_tty; /* Tty dependent stuff */ | 125 | el_tty_t el_tty; /* Tty dependent stuff */ | |
125 | el_refresh_t el_refresh; /* Refresh stuff */ | 126 | el_refresh_t el_refresh; /* Refresh stuff */ | |
126 | el_prompt_t el_prompt; /* Prompt stuff */ | 127 | el_prompt_t el_prompt; /* Prompt stuff */ | |
127 | el_prompt_t el_rprompt; /* Prompt stuff */ | 128 | el_prompt_t el_rprompt; /* Prompt stuff */ | |
129 | el_literal_t el_literal; /* prompt literal bits */ | |||
128 | el_chared_t el_chared; /* Characted editor stuff */ | 130 | el_chared_t el_chared; /* Characted editor stuff */ | |
129 | el_map_t el_map; /* Key mapping stuff */ | 131 | el_map_t el_map; /* Key mapping stuff */ | |
130 | el_keymacro_t el_keymacro; /* Key binding stuff */ | 132 | el_keymacro_t el_keymacro; /* Key binding stuff */ | |
131 | el_history_t el_history; /* History stuff */ | 133 | el_history_t el_history; /* History stuff */ | |
132 | el_search_t el_search; /* Search stuff */ | 134 | el_search_t el_search; /* Search stuff */ | |
133 | el_signal_t el_signal; /* Signal handling stuff */ | 135 | el_signal_t el_signal; /* Signal handling stuff */ | |
134 | struct el_read_t *el_read; /* Character reading stuff */ | 136 | struct el_read_t *el_read; /* Character reading stuff */ | |
135 | ct_buffer_t el_visual; /* Buffer for displayable str */ | 137 | ct_buffer_t el_visual; /* Buffer for displayable str */ | |
136 | ct_buffer_t el_scratch; /* Scratch conversion buffer */ | 138 | ct_buffer_t el_scratch; /* Scratch conversion buffer */ | |
137 | ct_buffer_t el_lgcyconv; /* Buffer for legacy wrappers */ | 139 | ct_buffer_t el_lgcyconv; /* Buffer for legacy wrappers */ | |
138 | LineInfo el_lgcylinfo; /* Legacy LineInfo buffer */ | 140 | LineInfo el_lgcylinfo; /* Legacy LineInfo buffer */ | |
139 | }; | 141 | }; | |
140 | 142 |
/* $NetBSD: literal.c,v 1.3.4.2 2017/07/23 14:41:26 snj Exp $ */
/*-
* Copyright (c) 2017 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Christos Zoulas.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "config.h"
#if !defined(lint) && !defined(SCCSID)
__RCSID("$NetBSD: literal.c,v 1.3.4.2 2017/07/23 14:41:26 snj Exp $");
#endif /* not lint && not SCCSID */
/*
* literal.c: Literal sequences handling.
*/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "el.h"
libedit_private void
literal_init(EditLine *el)
{
el_literal_t *l = &el->el_literal;
memset(l, 0, sizeof(*l));
}
libedit_private void
literal_end(EditLine *el)
{
literal_clear(el);
}
libedit_private void
literal_clear(EditLine *el)
{
el_literal_t *l = &el->el_literal;
size_t i;
if (l->l_len == 0)
return;
for (i = 0; i < l->l_idx; i++)
el_free(l->l_buf[i]);
el_free(l->l_buf);
l->l_buf = NULL;
l->l_len = 0;
l->l_idx = 0;
}
libedit_private wint_t
literal_add(EditLine *el, const wchar_t *buf, const wchar_t *end, int *wp)
{
el_literal_t *l = &el->el_literal;
size_t i, len;
ssize_t w, n;
char *b;
w = wcwidth(end[1]); /* column width of the visible char */
*wp = (int)w;
if (w <= 0) /* we require something to be printed */
return 0;
len = (size_t)(end - buf);
for (w = 0, i = 0; i < len; i++)
w += ct_enc_width(buf[i]);
w += ct_enc_width(end[1]);
b = el_malloc((size_t)(w + 1));
if (b == NULL)
return 0;
for (n = 0, i = 0; i < len; i++)
n += ct_encode_char(b + n, w - n, buf[i]);
n += ct_encode_char(b + n, w - n, end[1]);
b[n] = '\0';
/*
* Then save this literal string in the list of such strings,
* and return a "magic character" to put into the terminal buffer.
* When that magic char is 'printed' the saved string (which includes
* the char that belongs in that position) gets sent instead.
*/
if (l->l_idx == l->l_len) {
char **bp;
l->l_len += 4;
bp = el_realloc(l->l_buf, sizeof(*l->l_buf) * l->l_len);
if (bp == NULL) {
free(b);
l->l_len -= 4;
return 0;
}
l->l_buf = bp;
}
l->l_buf[l->l_idx++] = b;
return EL_LITERAL | (wint_t)(l->l_idx - 1);
}
libedit_private const char *
literal_get(EditLine *el, wint_t idx)
{
el_literal_t *l = &el->el_literal;
assert(idx & EL_LITERAL);
idx &= ~EL_LITERAL;
assert(l->l_idx > (size_t)idx);
return l->l_buf[idx];
}
/* $NetBSD: literal.h,v 1.2.4.2 2017/07/23 14:41:26 snj Exp $ */
/*-
* Copyright (c) 2017 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Christos Zoulas.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* el.literal.h: Literal character
*/
#ifndef _h_el_literal
#define _h_el_literal
#define EL_LITERAL ((wint_t)0x80000000)
typedef struct el_literal_t {
char **l_buf; /* array of buffers */
size_t l_idx; /* max in use */
size_t l_len; /* max allocated */
} el_literal_t;
libedit_private void literal_init(EditLine *);
libedit_private void literal_end(EditLine *);
libedit_private void literal_clear(EditLine *);
libedit_private wint_t literal_add(EditLine *, const wchar_t *,
const wchar_t *, int *);
libedit_private const char *literal_get(EditLine *, wint_t);
#endif /* _h_el_literal */
--- src/lib/libedit/prompt.c 2016/05/09 21:46:56 1.26
+++ src/lib/libedit/prompt.c 2017/07/23 14:41:26 1.26.8.1
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: prompt.c,v 1.26 2016/05/09 21:46:56 christos Exp $ */ | 1 | /* $NetBSD: prompt.c,v 1.26.8.1 2017/07/23 14:41:26 snj Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1992, 1993 | 4 | * Copyright (c) 1992, 1993 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to Berkeley by | 7 | * This code is derived from software contributed to Berkeley by | |
8 | * Christos Zoulas of Cornell University. | 8 | * Christos Zoulas of Cornell University. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -27,27 +27,27 @@ | @@ -27,27 +27,27 @@ | |||
27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
32 | * SUCH DAMAGE. | 32 | * SUCH DAMAGE. | |
33 | */ | 33 | */ | |
34 | 34 | |||
35 | #include "config.h" | 35 | #include "config.h" | |
36 | #if !defined(lint) && !defined(SCCSID) | 36 | #if !defined(lint) && !defined(SCCSID) | |
37 | #if 0 | 37 | #if 0 | |
38 | static char sccsid[] = "@(#)prompt.c 8.1 (Berkeley) 6/4/93"; | 38 | static char sccsid[] = "@(#)prompt.c 8.1 (Berkeley) 6/4/93"; | |
39 | #else | 39 | #else | |
40 | __RCSID("$NetBSD: prompt.c,v 1.26 2016/05/09 21:46:56 christos Exp $"); | 40 | __RCSID("$NetBSD: prompt.c,v 1.26.8.1 2017/07/23 14:41:26 snj Exp $"); | |
41 | #endif | 41 | #endif | |
42 | #endif /* not lint && not SCCSID */ | 42 | #endif /* not lint && not SCCSID */ | |
43 | 43 | |||
44 | /* | 44 | /* | |
45 | * prompt.c: Prompt printing functions | 45 | * prompt.c: Prompt printing functions | |
46 | */ | 46 | */ | |
47 | #include <stdio.h> | 47 | #include <stdio.h> | |
48 | #include "el.h" | 48 | #include "el.h" | |
49 | 49 | |||
50 | static wchar_t *prompt_default(EditLine *); | 50 | static wchar_t *prompt_default(EditLine *); | |
51 | static wchar_t *prompt_default_r(EditLine *); | 51 | static wchar_t *prompt_default_r(EditLine *); | |
52 | 52 | |||
53 | /* prompt_default(): | 53 | /* prompt_default(): | |
@@ -74,48 +74,51 @@ prompt_default_r(EditLine *el __attribut | @@ -74,48 +74,51 @@ prompt_default_r(EditLine *el __attribut | |||
74 | 74 | |||
75 | return a; | 75 | return a; | |
76 | } | 76 | } | |
77 | 77 | |||
78 | 78 | |||
79 | /* prompt_print(): | 79 | /* prompt_print(): | |
80 | * Print the prompt and update the prompt position. | 80 | * Print the prompt and update the prompt position. | |
81 | */ | 81 | */ | |
82 | libedit_private void | 82 | libedit_private void | |
83 | prompt_print(EditLine *el, int op) | 83 | prompt_print(EditLine *el, int op) | |
84 | { | 84 | { | |
85 | el_prompt_t *elp; | 85 | el_prompt_t *elp; | |
86 | wchar_t *p; | 86 | wchar_t *p; | |
87 | int ignore = 0; | |||
88 | 87 | |||
89 | if (op == EL_PROMPT) | 88 | if (op == EL_PROMPT) | |
90 | elp = &el->el_prompt; | 89 | elp = &el->el_prompt; | |
91 | else | 90 | else | |
92 | elp = &el->el_rprompt; | 91 | elp = &el->el_rprompt; | |
93 | 92 | |||
94 | if (elp->p_wide) | 93 | if (elp->p_wide) | |
95 | p = (*elp->p_func)(el); | 94 | p = (*elp->p_func)(el); | |
96 | else | 95 | else | |
97 | p = ct_decode_string((char *)(void *)(*elp->p_func)(el), | 96 | p = ct_decode_string((char *)(void *)(*elp->p_func)(el), | |
98 | &el->el_scratch); | 97 | &el->el_scratch); | |
99 | 98 | |||
100 | for (; *p; p++) { | 99 | for (; *p; p++) { | |
101 | if (elp->p_ignore == *p) { | 100 | if (elp->p_ignore == *p) { | |
102 | ignore = !ignore; | 101 | wchar_t *litstart = ++p; | |
102 | while (*p && *p != elp->p_ignore) | |||
103 | p++; | |||
104 | if (!*p || !p[1]) { | |||
105 | // XXX: We lose the last literal | |||
106 | break; | |||
107 | } | |||
108 | re_putliteral(el, litstart, p++); | |||
103 | continue; | 109 | continue; | |
104 | } | 110 | } | |
105 | if (ignore) | 111 | re_putc(el, *p, 1); | |
106 | terminal__putc(el, *p); | |||
107 | else | |||
108 | re_putc(el, *p, 1); | |||
109 | } | 112 | } | |
110 | 113 | |||
111 | elp->p_pos.v = el->el_refresh.r_cursor.v; | 114 | elp->p_pos.v = el->el_refresh.r_cursor.v; | |
112 | elp->p_pos.h = el->el_refresh.r_cursor.h; | 115 | elp->p_pos.h = el->el_refresh.r_cursor.h; | |
113 | } | 116 | } | |
114 | 117 | |||
115 | 118 | |||
116 | /* prompt_init(): | 119 | /* prompt_init(): | |
117 | * Initialize the prompt stuff | 120 | * Initialize the prompt stuff | |
118 | */ | 121 | */ | |
119 | libedit_private int | 122 | libedit_private int | |
120 | prompt_init(EditLine *el) | 123 | prompt_init(EditLine *el) | |
121 | { | 124 | { |
--- src/lib/libedit/read.c 2016/12/11 15:47:06 1.102
+++ src/lib/libedit/read.c 2017/07/23 14:41:26 1.102.6.1
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: read.c,v 1.102 2016/12/11 15:47:06 christos Exp $ */ | 1 | /* $NetBSD: read.c,v 1.102.6.1 2017/07/23 14:41:26 snj Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1992, 1993 | 4 | * Copyright (c) 1992, 1993 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to Berkeley by | 7 | * This code is derived from software contributed to Berkeley by | |
8 | * Christos Zoulas of Cornell University. | 8 | * Christos Zoulas of Cornell University. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -27,27 +27,27 @@ | @@ -27,27 +27,27 @@ | |||
27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
32 | * SUCH DAMAGE. | 32 | * SUCH DAMAGE. | |
33 | */ | 33 | */ | |
34 | 34 | |||
35 | #include "config.h" | 35 | #include "config.h" | |
36 | #if !defined(lint) && !defined(SCCSID) | 36 | #if !defined(lint) && !defined(SCCSID) | |
37 | #if 0 | 37 | #if 0 | |
38 | static char sccsid[] = "@(#)read.c 8.1 (Berkeley) 6/4/93"; | 38 | static char sccsid[] = "@(#)read.c 8.1 (Berkeley) 6/4/93"; | |
39 | #else | 39 | #else | |
40 | __RCSID("$NetBSD: read.c,v 1.102 2016/12/11 15:47:06 christos Exp $"); | 40 | __RCSID("$NetBSD: read.c,v 1.102.6.1 2017/07/23 14:41:26 snj Exp $"); | |
41 | #endif | 41 | #endif | |
42 | #endif /* not lint && not SCCSID */ | 42 | #endif /* not lint && not SCCSID */ | |
43 | 43 | |||
44 | /* | 44 | /* | |
45 | * read.c: Terminal read functions | 45 | * read.c: Terminal read functions | |
46 | */ | 46 | */ | |
47 | #include <ctype.h> | 47 | #include <ctype.h> | |
48 | #include <errno.h> | 48 | #include <errno.h> | |
49 | #include <fcntl.h> | 49 | #include <fcntl.h> | |
50 | #include <limits.h> | 50 | #include <limits.h> | |
51 | #include <stdlib.h> | 51 | #include <stdlib.h> | |
52 | #include <string.h> | 52 | #include <string.h> | |
53 | #include <unistd.h> | 53 | #include <unistd.h> | |
@@ -219,30 +219,29 @@ el_wpush(EditLine *el, const wchar_t *st | @@ -219,30 +219,29 @@ el_wpush(EditLine *el, const wchar_t *st | |||
219 | } | 219 | } | |
220 | 220 | |||
221 | 221 | |||
222 | /* read_getcmd(): | 222 | /* read_getcmd(): | |
223 | * Get next command from the input stream, | 223 | * Get next command from the input stream, | |
224 | * return 0 on success or -1 on EOF or error. | 224 | * return 0 on success or -1 on EOF or error. | |
225 | * Character values > 255 are not looked up in the map, but inserted. | 225 | * Character values > 255 are not looked up in the map, but inserted. | |
226 | */ | 226 | */ | |
227 | static int | 227 | static int | |
228 | read_getcmd(EditLine *el, el_action_t *cmdnum, wchar_t *ch) | 228 | read_getcmd(EditLine *el, el_action_t *cmdnum, wchar_t *ch) | |
229 | { | 229 | { | |
230 | static const wchar_t meta = (wchar_t)0x80; | 230 | static const wchar_t meta = (wchar_t)0x80; | |
231 | el_action_t cmd; | 231 | el_action_t cmd; | |
232 | int num; | |||
233 | 232 | |||
234 | do { | 233 | do { | |
235 | if ((num = el_wgetc(el, ch)) != 1) | 234 | if (el_wgetc(el, ch) != 1) | |
236 | return -1; | 235 | return -1; | |
237 | 236 | |||
238 | #ifdef KANJI | 237 | #ifdef KANJI | |
239 | if ((*ch & meta)) { | 238 | if ((*ch & meta)) { | |
240 | el->el_state.metanext = 0; | 239 | el->el_state.metanext = 0; | |
241 | cmd = CcViMap[' ']; | 240 | cmd = CcViMap[' ']; | |
242 | break; | 241 | break; | |
243 | } else | 242 | } else | |
244 | #endif /* KANJI */ | 243 | #endif /* KANJI */ | |
245 | 244 | |||
246 | if (el->el_state.metanext) { | 245 | if (el->el_state.metanext) { | |
247 | el->el_state.metanext = 0; | 246 | el->el_state.metanext = 0; | |
248 | *ch |= meta; | 247 | *ch |= meta; |
--- src/lib/libedit/refresh.c 2016/05/09 21:46:56 1.51
+++ src/lib/libedit/refresh.c 2017/07/23 14:41:26 1.51.8.1
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: refresh.c,v 1.51 2016/05/09 21:46:56 christos Exp $ */ | 1 | /* $NetBSD: refresh.c,v 1.51.8.1 2017/07/23 14:41:26 snj Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1992, 1993 | 4 | * Copyright (c) 1992, 1993 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to Berkeley by | 7 | * This code is derived from software contributed to Berkeley by | |
8 | * Christos Zoulas of Cornell University. | 8 | * Christos Zoulas of Cornell University. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -27,27 +27,27 @@ | @@ -27,27 +27,27 @@ | |||
27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
32 | * SUCH DAMAGE. | 32 | * SUCH DAMAGE. | |
33 | */ | 33 | */ | |
34 | 34 | |||
35 | #include "config.h" | 35 | #include "config.h" | |
36 | #if !defined(lint) && !defined(SCCSID) | 36 | #if !defined(lint) && !defined(SCCSID) | |
37 | #if 0 | 37 | #if 0 | |
38 | static char sccsid[] = "@(#)refresh.c 8.1 (Berkeley) 6/4/93"; | 38 | static char sccsid[] = "@(#)refresh.c 8.1 (Berkeley) 6/4/93"; | |
39 | #else | 39 | #else | |
40 | __RCSID("$NetBSD: refresh.c,v 1.51 2016/05/09 21:46:56 christos Exp $"); | 40 | __RCSID("$NetBSD: refresh.c,v 1.51.8.1 2017/07/23 14:41:26 snj Exp $"); | |
41 | #endif | 41 | #endif | |
42 | #endif /* not lint && not SCCSID */ | 42 | #endif /* not lint && not SCCSID */ | |
43 | 43 | |||
44 | /* | 44 | /* | |
45 | * refresh.c: Lower level screen refreshing functions | 45 | * refresh.c: Lower level screen refreshing functions | |
46 | */ | 46 | */ | |
47 | #include <stdio.h> | 47 | #include <stdio.h> | |
48 | #include <string.h> | 48 | #include <string.h> | |
49 | #include <unistd.h> | 49 | #include <unistd.h> | |
50 | 50 | |||
51 | #include "el.h" | 51 | #include "el.h" | |
52 | 52 | |||
53 | static void re_nextline(EditLine *); | 53 | static void re_nextline(EditLine *); | |
@@ -145,85 +145,117 @@ re_addc(EditLine *el, wint_t c) | @@ -145,85 +145,117 @@ re_addc(EditLine *el, wint_t c) | |||
145 | re_putc(el, c, 1); | 145 | re_putc(el, c, 1); | |
146 | break; | 146 | break; | |
147 | default: { | 147 | default: { | |
148 | wchar_t visbuf[VISUAL_WIDTH_MAX]; | 148 | wchar_t visbuf[VISUAL_WIDTH_MAX]; | |
149 | ssize_t i, n = | 149 | ssize_t i, n = | |
150 | ct_visual_char(visbuf, VISUAL_WIDTH_MAX, c); | 150 | ct_visual_char(visbuf, VISUAL_WIDTH_MAX, c); | |
151 | for (i = 0; n-- > 0; ++i) | 151 | for (i = 0; n-- > 0; ++i) | |
152 | re_putc(el, visbuf[i], 1); | 152 | re_putc(el, visbuf[i], 1); | |
153 | break; | 153 | break; | |
154 | } | 154 | } | |
155 | } | 155 | } | |
156 | } | 156 | } | |
157 | 157 | |||
158 | /* re_putliteral(): | |||
159 | * Place the literal string given | |||
160 | */ | |||
161 | libedit_private void | |||
162 | re_putliteral(EditLine *el, const wchar_t *begin, const wchar_t *end) | |||
163 | { | |||
164 | coord_t *cur = &el->el_refresh.r_cursor; | |||
165 | wint_t c; | |||
166 | int sizeh = el->el_terminal.t_size.h; | |||
167 | int i, w; | |||
168 | ||||
169 | c = literal_add(el, begin, end, &w); | |||
170 | if (c == 0 || w <= 0) | |||
171 | return; | |||
172 | el->el_vdisplay[cur->v][cur->h] = c; | |||
173 | ||||
174 | i = w; | |||
175 | if (i > sizeh - cur->h) /* avoid overflow */ | |||
176 | i = sizeh - cur->h; | |||
177 | while (--i > 0) | |||
178 | el->el_vdisplay[cur->v][cur->h + i] = MB_FILL_CHAR; | |||
179 | ||||
180 | cur->h += w; | |||
181 | if (cur->h >= sizeh) { | |||
182 | /* assure end of line */ | |||
183 | el->el_vdisplay[cur->v][sizeh] = '\0'; | |||
184 | re_nextline(el); | |||
185 | } | |||
186 | } | |||
158 | 187 | |||
159 | /* re_putc(): | 188 | /* re_putc(): | |
160 | * Draw the character given | 189 | * Draw the character given | |
161 | */ | 190 | */ | |
162 | libedit_private void | 191 | libedit_private void | |
163 | re_putc(EditLine *el, wint_t c, int shift) | 192 | re_putc(EditLine *el, wint_t c, int shift) | |
164 | { | 193 | { | |
194 | coord_t *cur = &el->el_refresh.r_cursor; | |||
165 | int i, w = wcwidth(c); | 195 | int i, w = wcwidth(c); | |
196 | int sizeh = el->el_terminal.t_size.h; | |||
197 | ||||
166 | ELRE_DEBUG(1, (__F, "printing %5x '%lc'\r\n", c, c)); | 198 | ELRE_DEBUG(1, (__F, "printing %5x '%lc'\r\n", c, c)); | |
167 | if (w == -1) | 199 | if (w == -1) | |
168 | w = 0; | 200 | w = 0; | |
169 | 201 | |||
170 | while (shift && (el->el_refresh.r_cursor.h + w > el->el_terminal.t_size.h)) | 202 | while (shift && (cur->h + w > sizeh)) | |
171 | re_putc(el, ' ', 1); | 203 | re_putc(el, ' ', 1); | |
172 | 204 | |||
173 | el->el_vdisplay[el->el_refresh.r_cursor.v] | 205 | el->el_vdisplay[cur->v][cur->h] = c; | |
174 | [el->el_refresh.r_cursor.h] = c; | |||
175 | /* assumes !shift is only used for single-column chars */ | 206 | /* assumes !shift is only used for single-column chars */ | |
176 | i = w; | 207 | i = w; | |
177 | while (--i > 0) | 208 | while (--i > 0) | |
178 | el->el_vdisplay[el->el_refresh.r_cursor.v] | 209 | el->el_vdisplay[cur->v][cur->h + i] = MB_FILL_CHAR; | |
179 | [el->el_refresh.r_cursor.h + i] = MB_FILL_CHAR; | |||
180 | 210 | |||
181 | if (!shift) | 211 | if (!shift) | |
182 | return; | 212 | return; | |
183 | 213 | |||
184 | el->el_refresh.r_cursor.h += w; /* advance to next place */ | 214 | cur->h += w; /* advance to next place */ | |
185 | if (el->el_refresh.r_cursor.h >= el->el_terminal.t_size.h) { | 215 | if (cur->h >= sizeh) { | |
186 | /* assure end of line */ | 216 | /* assure end of line */ | |
187 | el->el_vdisplay[el->el_refresh.r_cursor.v][el->el_terminal.t_size.h] | 217 | el->el_vdisplay[cur->v][sizeh] = '\0'; | |
188 | = '\0'; | |||
189 | re_nextline(el); | 218 | re_nextline(el); | |
190 | } | 219 | } | |
191 | } | 220 | } | |
192 | 221 | |||
193 | 222 | |||
194 | /* re_refresh(): | 223 | /* re_refresh(): | |
195 | * draws the new virtual screen image from the current input | 224 | * draws the new virtual screen image from the current input | |
196 | * line, then goes line-by-line changing the real image to the new | 225 | * line, then goes line-by-line changing the real image to the new | |
197 | * virtual image. The routine to re-draw a line can be replaced | 226 | * virtual image. The routine to re-draw a line can be replaced | |
198 | * easily in hopes of a smarter one being placed there. | 227 | * easily in hopes of a smarter one being placed there. | |
199 | */ | 228 | */ | |
200 | libedit_private void | 229 | libedit_private void | |
201 | re_refresh(EditLine *el) | 230 | re_refresh(EditLine *el) | |
202 | { | 231 | { | |
203 | int i, rhdiff; | 232 | int i, rhdiff; | |
204 | wchar_t *cp, *st; | 233 | wchar_t *cp, *st; | |
205 | coord_t cur; | 234 | coord_t cur; | |
206 | #ifdef notyet | 235 | #ifdef notyet | |
207 | size_t termsz; | 236 | size_t termsz; | |
208 | #endif | 237 | #endif | |
209 | 238 | |||
210 | ELRE_DEBUG(1, (__F, "el->el_line.buffer = :%ls:\r\n", | 239 | ELRE_DEBUG(1, (__F, "el->el_line.buffer = :%ls:\r\n", | |
211 | el->el_line.buffer)); | 240 | el->el_line.buffer)); | |
212 | 241 | |||
242 | literal_clear(el); | |||
213 | /* reset the Drawing cursor */ | 243 | /* reset the Drawing cursor */ | |
214 | el->el_refresh.r_cursor.h = 0; | 244 | el->el_refresh.r_cursor.h = 0; | |
215 | el->el_refresh.r_cursor.v = 0; | 245 | el->el_refresh.r_cursor.v = 0; | |
216 | 246 | |||
247 | terminal_move_to_char(el, 0); | |||
248 | ||||
217 | /* temporarily draw rprompt to calculate its size */ | 249 | /* temporarily draw rprompt to calculate its size */ | |
218 | prompt_print(el, EL_RPROMPT); | 250 | prompt_print(el, EL_RPROMPT); | |
219 | 251 | |||
220 | /* reset the Drawing cursor */ | 252 | /* reset the Drawing cursor */ | |
221 | el->el_refresh.r_cursor.h = 0; | 253 | el->el_refresh.r_cursor.h = 0; | |
222 | el->el_refresh.r_cursor.v = 0; | 254 | el->el_refresh.r_cursor.v = 0; | |
223 | 255 | |||
224 | if (el->el_line.cursor >= el->el_line.lastchar) { | 256 | if (el->el_line.cursor >= el->el_line.lastchar) { | |
225 | if (el->el_map.current == el->el_map.alt | 257 | if (el->el_map.current == el->el_map.alt | |
226 | && el->el_line.lastchar != el->el_line.buffer) | 258 | && el->el_line.lastchar != el->el_line.buffer) | |
227 | el->el_line.cursor = el->el_line.lastchar - 1; | 259 | el->el_line.cursor = el->el_line.lastchar - 1; | |
228 | else | 260 | else | |
229 | el->el_line.cursor = el->el_line.lastchar; | 261 | el->el_line.cursor = el->el_line.lastchar; |
--- src/lib/libedit/refresh.h 2016/05/09 21:46:56 1.10
+++ src/lib/libedit/refresh.h 2017/07/23 14:41:26 1.10.8.1
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: refresh.h,v 1.10 2016/05/09 21:46:56 christos Exp $ */ | 1 | /* $NetBSD: refresh.h,v 1.10.8.1 2017/07/23 14:41:26 snj Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1992, 1993 | 4 | * Copyright (c) 1992, 1993 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to Berkeley by | 7 | * This code is derived from software contributed to Berkeley by | |
8 | * Christos Zoulas of Cornell University. | 8 | * Christos Zoulas of Cornell University. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -37,21 +37,23 @@ | @@ -37,21 +37,23 @@ | |||
37 | /* | 37 | /* | |
38 | * el.refresh.h: Screen refresh functions | 38 | * el.refresh.h: Screen refresh functions | |
39 | */ | 39 | */ | |
40 | #ifndef _h_el_refresh | 40 | #ifndef _h_el_refresh | |
41 | #define _h_el_refresh | 41 | #define _h_el_refresh | |
42 | 42 | |||
43 | typedef struct { | 43 | typedef struct { | |
44 | coord_t r_cursor; /* Refresh cursor position */ | 44 | coord_t r_cursor; /* Refresh cursor position */ | |
45 | int r_oldcv; /* Vertical locations */ | 45 | int r_oldcv; /* Vertical locations */ | |
46 | int r_newcv; | 46 | int r_newcv; | |
47 | } el_refresh_t; | 47 | } el_refresh_t; | |
48 | 48 | |||
49 | libedit_private void re_putc(EditLine *, wint_t, int); | 49 | libedit_private void re_putc(EditLine *, wint_t, int); | |
50 | libedit_private void re_putliteral(EditLine *, const wchar_t *, | |||
51 | const wchar_t *); | |||
50 | libedit_private void re_clear_lines(EditLine *); | 52 | libedit_private void re_clear_lines(EditLine *); | |
51 | libedit_private void re_clear_display(EditLine *); | 53 | libedit_private void re_clear_display(EditLine *); | |
52 | libedit_private void re_refresh(EditLine *); | 54 | libedit_private void re_refresh(EditLine *); | |
53 | libedit_private void re_refresh_cursor(EditLine *); | 55 | libedit_private void re_refresh_cursor(EditLine *); | |
54 | libedit_private void re_fastaddc(EditLine *); | 56 | libedit_private void re_fastaddc(EditLine *); | |
55 | libedit_private void re_goto_bottom(EditLine *); | 57 | libedit_private void re_goto_bottom(EditLine *); | |
56 | 58 | |||
57 | #endif /* _h_el_refresh */ | 59 | #endif /* _h_el_refresh */ |