Commit d96c25a7 authored by Nirbhay Choubey's avatar Nirbhay Choubey

WL#5945 : Improve libedit library

Updated libedit library.
parent 6d590649
...@@ -7,19 +7,19 @@ INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include ...@@ -7,19 +7,19 @@ INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include
noinst_LIBRARIES = libedit.a noinst_LIBRARIES = libedit.a
libedit_a_SOURCES = chared.c el.c history.c map.c prompt.c readline.c \ libedit_a_SOURCES = chared.c el.c eln.c history.c historyn.c map.c prompt.c readline.c \
search.c tokenizer.c vi.c common.c emacs.c \ search.c tokenizer.c tokenizern.c vi.c common.c emacs.c \
hist.c key.c parse.c read.c refresh.c sig.c term.c \ hist.c keymacro.c parse.c read.c refresh.c sig.c terminal.c \
tty.c help.c fcns.c filecomplete.c \ tty.c help.c fcns.c filecomplete.c \
np/unvis.c np/strlcpy.c np/vis.c np/strlcat.c \ np/unvis.c np/strlcpy.c np/vis.c np/strlcat.c \
np/fgetln.c np/fgetln.c np/wcsdup.c
libedit_a_LIBADD = @LIBEDIT_LOBJECTS@ libedit_a_LIBADD = @LIBEDIT_LOBJECTS@
libedit_a_DEPENDENCIES = @LIBEDIT_LOBJECTS@ libedit_a_DEPENDENCIES = @LIBEDIT_LOBJECTS@
pkginclude_HEADERS = readline/readline.h pkginclude_HEADERS = readline/readline.h
noinst_HEADERS = chared.h el.h el_term.h histedit.h key.h parse.h refresh.h sig.h \ noinst_HEADERS = chared.h el.h el_terminal.h histedit.h keymacro.h parse.h refresh.h sig.h \
sys.h config.h hist.h map.h prompt.h read.h \ sys.h config.h hist.h map.h prompt.h read.h \
search.h tty.h filecomplete.h np/vis.h search.h tty.h filecomplete.h np/vis.h
...@@ -70,22 +70,25 @@ fcns.c: ${AHDR} fcns.h makelist ...@@ -70,22 +70,25 @@ fcns.c: ${AHDR} fcns.h makelist
chared.o: vi.h emacs.h common.h help.h fcns.h chared.o: vi.h emacs.h common.h help.h fcns.h
el.o: vi.h emacs.h common.h help.h fcns.h el.o: vi.h emacs.h common.h help.h fcns.h
eln.o: vi.h emacs.h common.h help.h fcns.h
history.o: vi.h emacs.h common.h help.h fcns.h history.o: vi.h emacs.h common.h help.h fcns.h
historyn.o: vi.h emacs.h common.h help.h fcns.h
map.o: vi.h emacs.h common.h help.h fcns.h map.o: vi.h emacs.h common.h help.h fcns.h
prompt.o: vi.h emacs.h common.h help.h fcns.h prompt.o: vi.h emacs.h common.h help.h fcns.h
readline.o: vi.h emacs.h common.h help.h fcns.h readline.o: vi.h emacs.h common.h help.h fcns.h
search.o: vi.h emacs.h common.h help.h fcns.h search.o: vi.h emacs.h common.h help.h fcns.h
tokenizer.o: vi.h emacs.h common.h help.h fcns.h tokenizer.o: vi.h emacs.h common.h help.h fcns.h
tokenizern.o: vi.h emacs.h common.h help.h fcns.h
vi.o: vi.h emacs.h common.h help.h fcns.h vi.o: vi.h emacs.h common.h help.h fcns.h
common.o: vi.h emacs.h common.h help.h fcns.h common.o: vi.h emacs.h common.h help.h fcns.h
emacs.o: vi.h emacs.h common.h help.h fcns.h emacs.o: vi.h emacs.h common.h help.h fcns.h
hist.o: vi.h emacs.h common.h help.h fcns.h hist.o: vi.h emacs.h common.h help.h fcns.h
key.o: vi.h emacs.h common.h help.h fcns.h keymacro.o: vi.h emacs.h common.h help.h fcns.h
parse.o: vi.h emacs.h common.h help.h fcns.h parse.o: vi.h emacs.h common.h help.h fcns.h
read.o: vi.h emacs.h common.h help.h fcns.h read.o: vi.h emacs.h common.h help.h fcns.h
refresh.o: vi.h emacs.h common.h help.h fcns.h refresh.o: vi.h emacs.h common.h help.h fcns.h
sig.o: vi.h emacs.h common.h help.h fcns.h sig.o: vi.h emacs.h common.h help.h fcns.h
term.o: vi.h emacs.h common.h help.h fcns.h terminal.o: vi.h emacs.h common.h help.h fcns.h
tty.o: vi.h emacs.h common.h help.h fcns.h tty.o: vi.h emacs.h common.h help.h fcns.h
help.o: vi.h emacs.h common.h help.h fcns.h help.o: vi.h emacs.h common.h help.h fcns.h
fcns.o: vi.h emacs.h common.h help.h fcns.h fcns.o: vi.h emacs.h common.h help.h fcns.h
......
...@@ -2,7 +2,7 @@ An approximate method to merge from upstream is: ...@@ -2,7 +2,7 @@ An approximate method to merge from upstream is:
# Fetch latest from upstream (we also include some compat stuff) # Fetch latest from upstream (we also include some compat stuff)
$ CVS_RSH=ssh; export CVS_RSH $ CVS_RSH=ssh; export CVS_RSH
$ CVSROOT="anoncvs@stripped:/cvsroot" $ CVSROOT="anoncvs@anoncvs.netbsd.org:/cvsroot"
$ cvs co -d libedit -P src/lib/libedit $ cvs co -d libedit -P src/lib/libedit
$ mkdir libedit/np $ mkdir libedit/np
$ for f in src/common/lib/libc/string/strlcat.c \ $ for f in src/common/lib/libc/string/strlcat.c \
...@@ -24,13 +24,13 @@ An approximate method to merge from upstream is: ...@@ -24,13 +24,13 @@ An approximate method to merge from upstream is:
# Rename files to match our naming # Rename files to match our naming
$ mv makelist makelist.sh $ mv makelist makelist.sh
$ mv term.h el_term.h $ mv terminal.h el_terminal.h
# Remove NetBSD-specific bits # Remove NetBSD-specific bits
$ for file in $(find . -type f) $ for file in $(find . -type f)
> do > do
> cp ${file} ${file}.orig > cp ${file} ${file}.orig
> sed -e 's/#include "term.h"/#include "el_term.h"/g' \ > sed -e 's/#include "terminal.h"/#include "el_terminal.h"/g' \
> -e 's/sig_handler/el_sig_handler/g' \ > -e 's/sig_handler/el_sig_handler/g' \
> -e 's/isprint/el_isprint/g' \ > -e 's/isprint/el_isprint/g' \
> -e '/^__RCSID/d' \ > -e '/^__RCSID/d' \
...@@ -42,9 +42,9 @@ then merge remaining bits by hand. All MySQL-specific changes should be ...@@ -42,9 +42,9 @@ then merge remaining bits by hand. All MySQL-specific changes should be
marked with XXXMYSQL to make them easier to identify and merge. To generate marked with XXXMYSQL to make them easier to identify and merge. To generate
a 'clean' diff against upstream you can use the above commands but use a 'clean' diff against upstream you can use the above commands but use
cvs co -D "2009/02/06 20:09:00" [..] cvs co -D "2011/10/04 15:27:04" [..]
to fetch the baseline of most recent merge. to fetch the baseline of most recent merge.
Please feed any fixes to Jonathan Perkin <jperkin@stripped> who will endeavour Please feed any fixes to Jonathan Perkin <jonathan.perkin@oracle.com> who will
to merge them upstream and keep diffs minimal. endeavour to merge them upstream and keep diffs minimal.
This diff is collapsed.
/* $NetBSD: chared.h,v 1.17 2006/03/06 21:11:56 christos Exp $ */ /* $NetBSD: chared.h,v 1.21 2010/08/28 15:44:59 christos Exp $ */
/*- /*-
* Copyright (c) 1992, 1993 * Copyright (c) 1992, 1993
...@@ -63,25 +63,25 @@ ...@@ -63,25 +63,25 @@
typedef struct c_macro_t { typedef struct c_macro_t {
int level; int level;
int offset; int offset;
char **macro; Char **macro;
} c_macro_t; } c_macro_t;
/* /*
* Undo information for vi - no undo in emacs (yet) * Undo information for vi - no undo in emacs (yet)
*/ */
typedef struct c_undo_t { typedef struct c_undo_t {
int len; /* length of saved line */ ssize_t len; /* length of saved line */
int cursor; /* position of saved cursor */ int cursor; /* position of saved cursor */
char *buf; /* full saved text */ Char *buf; /* full saved text */
} c_undo_t; } c_undo_t;
/* redo for vi */ /* redo for vi */
typedef struct c_redo_t { typedef struct c_redo_t {
char *buf; /* redo insert key sequence */ Char *buf; /* redo insert key sequence */
char *pos; Char *pos;
char *lim; Char *lim;
el_action_t cmd; /* command to redo */ el_action_t cmd; /* command to redo */
char ch; /* char that invoked it */ Char ch; /* char that invoked it */
int count; int count;
int action; /* from cv_action() */ int action; /* from cv_action() */
} c_redo_t; } c_redo_t;
...@@ -91,18 +91,20 @@ typedef struct c_redo_t { ...@@ -91,18 +91,20 @@ typedef struct c_redo_t {
*/ */
typedef struct c_vcmd_t { typedef struct c_vcmd_t {
int action; int action;
char *pos; Char *pos;
} c_vcmd_t; } c_vcmd_t;
/* /*
* Kill buffer for emacs * Kill buffer for emacs
*/ */
typedef struct c_kill_t { typedef struct c_kill_t {
char *buf; Char *buf;
char *last; Char *last;
char *mark; Char *mark;
} c_kill_t; } c_kill_t;
typedef void (*el_zfunc_t)(EditLine *, void *);
/* /*
* Note that we use both data structures because the user can bind * Note that we use both data structures because the user can bind
* commands from both editors! * commands from both editors!
...@@ -113,13 +115,14 @@ typedef struct el_chared_t { ...@@ -113,13 +115,14 @@ typedef struct el_chared_t {
c_redo_t c_redo; c_redo_t c_redo;
c_vcmd_t c_vcmd; c_vcmd_t c_vcmd;
c_macro_t c_macro; c_macro_t c_macro;
el_zfunc_t c_resizefun;
void * c_resizearg;
} el_chared_t; } el_chared_t;
#define STRQQ "\"\"" #define STRQQ "\"\""
#define isglob(a) (strchr("*[]?", (a)) != NULL) #define isglob(a) (strchr("*[]?", (a)) != NULL)
#define isword(a) (el_isprint(a))
#define NOP 0x00 #define NOP 0x00
#define DELETE 0x01 #define DELETE 0x01
...@@ -140,27 +143,28 @@ typedef struct el_chared_t { ...@@ -140,27 +143,28 @@ typedef struct el_chared_t {
#include "fcns.h" #include "fcns.h"
protected int cv__isword(int); protected int cv__isword(Int);
protected int cv__isWord(int); protected int cv__isWord(Int);
protected void cv_delfini(EditLine *); protected void cv_delfini(EditLine *);
protected char *cv__endword(char *, char *, int, int (*)(int)); protected Char *cv__endword(Char *, Char *, int, int (*)(Int));
protected int ce__isword(int); protected int ce__isword(Int);
protected void cv_undo(EditLine *); protected void cv_undo(EditLine *);
protected void cv_yank(EditLine *, const char *, int); protected void cv_yank(EditLine *, const Char *, int);
protected char *cv_next_word(EditLine*, char *, char *, int, int (*)(int)); protected Char *cv_next_word(EditLine*, Char *, Char *, int, int (*)(Int));
protected char *cv_prev_word(char *, char *, int, int (*)(int)); protected Char *cv_prev_word(Char *, Char *, int, int (*)(Int));
protected char *c__next_word(char *, char *, int, int (*)(int)); protected Char *c__next_word(Char *, Char *, int, int (*)(Int));
protected char *c__prev_word(char *, char *, int, int (*)(int)); protected Char *c__prev_word(Char *, Char *, int, int (*)(Int));
protected void c_insert(EditLine *, int); protected void c_insert(EditLine *, int);
protected void c_delbefore(EditLine *, int); protected void c_delbefore(EditLine *, int);
protected void c_delbefore1(EditLine *); protected void c_delbefore1(EditLine *);
protected void c_delafter(EditLine *, int); protected void c_delafter(EditLine *, int);
protected void c_delafter1(EditLine *); protected void c_delafter1(EditLine *);
protected int c_gets(EditLine *, char *, const char *); protected int c_gets(EditLine *, Char *, const Char *);
protected int c_hpos(EditLine *); protected int c_hpos(EditLine *);
protected int ch_init(EditLine *); protected int ch_init(EditLine *);
protected void ch_reset(EditLine *, int); protected void ch_reset(EditLine *, int);
protected int ch_resizefun(EditLine *, el_zfunc_t, void *);
protected int ch_enlargebufs(EditLine *, size_t); protected int ch_enlargebufs(EditLine *, size_t);
protected void ch_end(EditLine *); protected void ch_end(EditLine *);
......
/* $NetBSD: chartype.c,v 1.10 2011/08/16 16:25:15 christos Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
*/
/*
* chartype.c: character classification and meta information
*/
#include "config.h"
#if !defined(lint) && !defined(SCCSID)
#endif /* not lint && not SCCSID */
#include "el.h"
#include <stdlib.h>
#define CT_BUFSIZ ((size_t)1024)
#ifdef WIDECHAR
protected void
ct_conv_buff_resize(ct_buffer_t *conv, size_t mincsize, size_t minwsize)
{
void *p;
if (mincsize > conv->csize) {
conv->csize = mincsize;
p = el_realloc(conv->cbuff, conv->csize * sizeof(*conv->cbuff));
if (p == NULL) {
conv->csize = 0;
el_free(conv->cbuff);
conv->cbuff = NULL;
} else
conv->cbuff = p;
}
if (minwsize > conv->wsize) {
conv->wsize = minwsize;
p = el_realloc(conv->wbuff, conv->wsize * sizeof(*conv->wbuff));
if (p == NULL) {
conv->wsize = 0;
el_free(conv->wbuff);
conv->wbuff = NULL;
} else
conv->wbuff = p;
}
}
public char *
ct_encode_string(const Char *s, ct_buffer_t *conv)
{
char *dst;
ssize_t used = 0;
mbstate_t state;
memset(&state, 0, sizeof(mbstate_t));
if (!s)
return NULL;
if (!conv->cbuff)
ct_conv_buff_resize(conv, CT_BUFSIZ, (size_t)0);
if (!conv->cbuff)
return NULL;
dst = conv->cbuff;
while (*s) {
used = (ssize_t)(conv->csize - (size_t)(dst - conv->cbuff));
if (used < 5) {
used = dst - conv->cbuff;
ct_conv_buff_resize(conv, conv->csize + CT_BUFSIZ,
(size_t)0);
if (!conv->cbuff)
return NULL;
dst = conv->cbuff + used;
}
used = ct_encode_char(dst, (size_t)5, *s, &state);
if (used == -1) /* failed to encode, need more buffer space */
abort();
++s;
dst += used;
}
*dst = '\0';
return conv->cbuff;
}
public Char *
ct_decode_string(const char *s, ct_buffer_t *conv)
{
size_t len = 0;
if (!s)
return NULL;
if (!conv->wbuff)
ct_conv_buff_resize(conv, (size_t)0, CT_BUFSIZ);
if (!conv->wbuff)
return NULL;
len = ct_mbstowcs(NULL, s, (size_t)0);
if (len == (size_t)-1)
return NULL;
if (len > conv->wsize)
ct_conv_buff_resize(conv, (size_t)0, len + 1);
if (!conv->wbuff)
return NULL;
ct_mbstowcs(conv->wbuff, s, conv->wsize);
return conv->wbuff;
}
protected Char **
ct_decode_argv(int argc, const char *argv[], ct_buffer_t *conv)
{
size_t bufspace;
int i;
Char *p;
Char **wargv;
ssize_t bytes;
mbstate_t state;
/* Make sure we have enough space in the conversion buffer to store all
* the argv strings. */
for (i = 0, bufspace = 0; i < argc; ++i)
bufspace += argv[i] ? strlen(argv[i]) + 1 : 0;
ct_conv_buff_resize(conv, (size_t)0, bufspace);
if (!conv->wsize)
return NULL;
wargv = el_malloc((size_t)argc * sizeof(*wargv));
for (i = 0, p = conv->wbuff; i < argc; ++i) {
if (!argv[i]) { /* don't pass null pointers to mbsrtowcs */
wargv[i] = NULL;
continue;
} else {
wargv[i] = p;
memset(&state, 0, sizeof(mbstate_t));
bytes = (ssize_t)mbsrtowcs(p, argv + i, bufspace, &state);
}
if (bytes == -1) {
el_free(wargv);
return NULL;
} else
bytes++; /* include '\0' in the count */
bufspace -= (size_t)bytes;
p += bytes;
}
return wargv;
}
protected size_t
ct_enc_width(Char c)
{
/* UTF-8 encoding specific values */
if (c < 0x80)
return 1;
else if (c < 0x0800)
return 2;
else if (c < 0x10000)
return 3;
else if (c < 0x110000)
return 4;
else
return 0; /* not a valid codepoint */
}
protected ssize_t
ct_encode_char(char *dst, size_t len, Char c, mbstate_t *state)
{
ssize_t l = 0;
if (len < ct_enc_width(c))
return -1;
l = wcrtomb(dst, c, state);
if (l < 0) {
memset (state, 0, sizeof (mbstate_t));
l = 0;
}
return l;
}
#endif
protected const Char *
ct_visual_string(const Char *s)
{
static Char *buff = NULL;
static size_t buffsize = 0;
void *p;
Char *dst;
ssize_t used = 0;
if (!s)
return NULL;
if (!buff) {
buffsize = CT_BUFSIZ;
buff = el_malloc(buffsize * sizeof(*buff));
}
dst = buff;
while (*s) {
used = ct_visual_char(dst, buffsize - (size_t)(dst - buff), *s);
if (used == -1) { /* failed to encode, need more buffer space */
used = dst - buff;
buffsize += CT_BUFSIZ;
p = el_realloc(buff, buffsize * sizeof(*buff));
if (p == NULL)
goto out;
buff = p;
dst = buff + used;
/* don't increment s here - we want to retry it! */
}
else
++s;
dst += used;
}
if (dst >= (buff + buffsize)) { /* sigh */
buffsize += 1;
p = el_realloc(buff, buffsize * sizeof(*buff));
if (p == NULL)
goto out;
buff = p;
dst = buff + buffsize - 1;
}
*dst = 0;
return buff;
out:
el_free(buff);
buffsize = 0;
return NULL;
}
#ifdef WIDECHAR
int wcwidth(wchar_t wc); // Signature.
#endif
protected int
ct_visual_width(Char c)
{
int t = ct_chr_class(c);
switch (t) {
case CHTYPE_ASCIICTL:
return 2; /* ^@ ^? etc. */
case CHTYPE_TAB:
return 1; /* Hmm, this really need to be handled outside! */
case CHTYPE_NL:
return 0; /* Should this be 1 instead? */
#ifdef WIDECHAR
case CHTYPE_PRINT:
return wcwidth(c);
case CHTYPE_NONPRINT:
if (c > 0xffff) /* prefer standard 4-byte display over 5-byte */
return 8; /* \U+12345 */
else
return 7; /* \U+1234 */
#else
case CHTYPE_PRINT:
return 1;
case CHTYPE_NONPRINT:
return 4; /* \123 */
#endif
default:
return 0; /* should not happen */
}
}
protected ssize_t
ct_visual_char(Char *dst, size_t len, Char c)
{
int t = ct_chr_class(c);
switch (t) {
case CHTYPE_TAB:
case CHTYPE_NL:
case CHTYPE_ASCIICTL:
if (len < 2)
return -1; /* insufficient space */
*dst++ = '^';
if (c == '\177')
*dst = '?'; /* DEL -> ^? */
else
*dst = c | 0100; /* uncontrolify it */
return 2;
case CHTYPE_PRINT:
if (len < 1)
return -1; /* insufficient space */
*dst = c;
return 1;
case CHTYPE_NONPRINT:
/* we only use single-width glyphs for display,
* so this is right */
if ((ssize_t)len < ct_visual_width(c))
return -1; /* insufficient space */
#ifdef WIDECHAR
*dst++ = '\\';
*dst++ = 'U';
*dst++ = '+';
#define tohexdigit(v) "0123456789ABCDEF"[v]
if (c > 0xffff) /* prefer standard 4-byte display over 5-byte */
*dst++ = tohexdigit(((unsigned int) c >> 16) & 0xf);
*dst++ = tohexdigit(((unsigned int) c >> 12) & 0xf);
*dst++ = tohexdigit(((unsigned int) c >> 8) & 0xf);
*dst++ = tohexdigit(((unsigned int) c >> 4) & 0xf);
*dst = tohexdigit(((unsigned int) c ) & 0xf);
return c > 0xffff ? 8 : 7;
#else
*dst++ = '\\';
#define tooctaldigit(v) ((v) + '0')
*dst++ = tooctaldigit(((unsigned int) c >> 6) & 0x7);
*dst++ = tooctaldigit(((unsigned int) c >> 3) & 0x7);
*dst++ = tooctaldigit(((unsigned int) c ) & 0x7);
#endif
/*FALLTHROUGH*/
/* these two should be handled outside this function */
default: /* we should never hit the default */
return 0;
}
}
protected int
ct_chr_class(Char c)
{
if (c == '\t')
return CHTYPE_TAB;
else if (c == '\n')
return CHTYPE_NL;
else if (IsASCII(c) && Iscntrl(c))
return CHTYPE_ASCIICTL;
else if (Isprint(c))
return CHTYPE_PRINT;
else
return CHTYPE_NONPRINT;
}
/* $NetBSD: chartype.h,v 1.8 2011/07/29 23:44:44 christos Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
*/
#ifndef _h_chartype_f
#define _h_chartype_f
#ifdef WIDECHAR
/* Ideally we should also test the value of the define to see if it
* supports non-BMP code points without requiring UTF-16, but nothing
* seems to actually advertise this properly, despite Unicode 3.1 having
* been around since 2001... */
/* XXXMYSQL : Added FreeBSD to bypass this check.
TODO : Verify if FreeBSD stores ISO 10646 in wchar_t. */
#if !defined(__NetBSD__) && !defined(__sun) \
&& !(defined(__APPLE__) && defined(__MACH__)) \
&& !defined(__FreeBSD__)
#ifndef __STDC_ISO_10646__
/* In many places it is assumed that the first 127 code points are ASCII
* compatible, so ensure wchar_t indeed does ISO 10646 and not some other
* funky encoding that could break us in weird and wonderful ways. */
#error wchar_t must store ISO 10646 characters
#endif
#endif
/* Oh for a <uchar.h> with char32_t and __STDC_UTF_32__ in it...
* ref: ISO/IEC DTR 19769
*/
#if WCHAR_MAX < INT32_MAX
#warning Build environment does not support non-BMP characters
#endif
#ifndef HAVE_WCSDUP
wchar_t *wcsdup(const wchar_t *s);
#endif
#define ct_wctomb wctomb
#define ct_wctomb_reset wctomb(0,0)
#define ct_wcstombs wcstombs
#define ct_mbstowcs mbstowcs
#define Char wchar_t
#define Int wint_t
#define FUN(prefix,rest) prefix ## _w ## rest
#define FUNW(type) type ## _w
#define TYPE(type) type ## W
#define FSTR "%ls"
#define STR(x) L ## x
#define UC(c) c
#define Isalpha(x) iswalpha(x)
#define Isalnum(x) iswalnum(x)
#define Isgraph(x) iswgraph(x)
#define Isspace(x) iswspace(x)
#define Isdigit(x) iswdigit(x)
#define Iscntrl(x) iswcntrl(x)
#define Isprint(x) iswprint(x)
#define Isupper(x) iswupper(x)
#define Islower(x) iswlower(x)
#define Toupper(x) towupper(x)
#define Tolower(x) towlower(x)
#define IsASCII(x) (x < 0x100)
#define Strlen(x) wcslen(x)
#define Strchr(s,c) wcschr(s,c)
#define Strrchr(s,c) wcsrchr(s,c)
#define Strstr(s,v) wcsstr(s,v)
#define Strdup(x) wcsdup(x)
#define Strcpy(d,s) wcscpy(d,s)
#define Strncpy(d,s,n) wcsncpy(d,s,n)
#define Strncat(d,s,n) wcsncat(d,s,n)
#define Strcmp(s,v) wcscmp(s,v)
#define Strncmp(s,v,n) wcsncmp(s,v,n)
#define Strcspn(s,r) wcscspn(s,r)
#define Strtol(p,e,b) wcstol(p,e,b)
#define Width(c) wcwidth(c)
#else /* NARROW */
#define ct_mbtowc error
#define ct_mbtowc_reset
#define ct_wctomb error
#define ct_wctomb_reset
#define ct_wcstombs(a, b, c) (strncpy(a, b, c), strlen(a))
#define ct_mbstowcs(a, b, c) (strncpy(a, b, c), strlen(a))
#define Char char
#define Int int
#define FUN(prefix,rest) prefix ## _ ## rest
#define FUNW(type) type
#define TYPE(type) type
#define FSTR "%s"
#define STR(x) x
#define UC(c) (unsigned char)(c)
#define Isalpha(x) isalpha((unsigned char)x)
#define Isalnum(x) isalnum((unsigned char)x)
#define Isgraph(x) isgraph((unsigned char)x)
#define Isspace(x) isspace((unsigned char)x)
#define Isdigit(x) isdigit((unsigned char)x)
#define Iscntrl(x) iscntrl((unsigned char)x)
#define Isprint(x) isprint((unsigned char)x)
#define Isupper(x) isupper((unsigned char)x)
#define Islower(x) islower((unsigned char)x)
#define Toupper(x) toupper((unsigned char)x)
#define Tolower(x) tolower((unsigned char)x)
#define IsASCII(x) isascii((unsigned char)x)
#define Strlen(x) strlen(x)
#define Strchr(s,c) strchr(s,c)
#define Strrchr(s,c) strrchr(s,c)
#define Strstr(s,v) strstr(s,v)
#define Strdup(x) strdup(x)
#define Strcpy(d,s) strcpy(d,s)
#define Strncpy(d,s,n) strncpy(d,s,n)
#define Strncat(d,s,n) strncat(d,s,n)
#define Strcmp(s,v) strcmp(s,v)
#define Strncmp(s,v,n) strncmp(s,v,n)
#define Strcspn(s,r) strcspn(s,r)
#define Strtol(p,e,b) strtol(p,e,b)
#define Width(c) 1
#endif
#ifdef WIDECHAR
/*
* Conversion buffer
*/
typedef struct ct_buffer_t {
char *cbuff;
size_t csize;
Char *wbuff;
size_t wsize;
} ct_buffer_t;
#define ct_encode_string __ct_encode_string
/* Encode a wide-character string and return the UTF-8 encoded result. */
public char *ct_encode_string(const Char *, ct_buffer_t *);
#define ct_decode_string __ct_decode_string
/* Decode a (multi)?byte string and return the wide-character string result. */
public Char *ct_decode_string(const char *, ct_buffer_t *);
/* Decode a (multi)?byte argv string array.
* The pointer returned must be free()d when done. */
protected Char **ct_decode_argv(int, const char *[], ct_buffer_t *);
/* Resizes the conversion buffer(s) if needed. */
protected void ct_conv_buff_resize(ct_buffer_t *, size_t, size_t);
protected ssize_t ct_encode_char(char *, size_t, Char, mbstate_t *);
protected size_t ct_enc_width(Char);
#define ct_free_argv(s) el_free(s)
#else
#define ct_encode_string(s, b) (s)
#define ct_decode_string(s, b) (s)
#define ct_decode_argv(l, s, b) (s)
#define ct_conv_buff_resize(b, os, ns)
#define ct_encode_char(d, l, s, ps) (*d = s, 1)
#define ct_free_argv(s)
#endif
#ifndef NARROWCHAR
/* Encode a characted into the destination buffer, provided there is sufficent
* buffer space available. Returns the number of bytes used up (zero if the
* character cannot be encoded, -1 if there was not enough space available). */
/* The maximum buffer size to hold the most unwieldly visual representation,
* in this case \U+nnnnn. */
#define VISUAL_WIDTH_MAX ((size_t)8)
/* The terminal is thought of in terms of X columns by Y lines. In the cases
* where a wide character takes up more than one column, the adjacent
* occupied column entries will contain this faux character. */
#define MB_FILL_CHAR ((Char)-1)
/* Visual width of character c, taking into account ^? , \0177 and \U+nnnnn
* style visual expansions. */
protected int ct_visual_width(Char);
/* Turn the given character into the appropriate visual format, matching
* the width given by ct_visual_width(). Returns the number of characters used
* up, or -1 if insufficient space. Buffer length is in count of Char's. */
protected ssize_t ct_visual_char(Char *, size_t, Char);
/* Convert the given string into visual format, using the ct_visual_char()
* function. Uses a static buffer, so not threadsafe. */
protected const Char *ct_visual_string(const Char *);
/* printable character, use ct_visual_width() to find out display width */
#define CHTYPE_PRINT ( 0)
/* control character found inside the ASCII portion of the charset */
#define CHTYPE_ASCIICTL (-1)
/* a \t */
#define CHTYPE_TAB (-2)
/* a \n */
#define CHTYPE_NL (-3)
/* non-printable character */
#define CHTYPE_NONPRINT (-4)
/* classification of character c, as one of the above defines */
protected int ct_chr_class(Char c);
#endif
#endif /* _chartype_f */
This diff is collapsed.
#include "my_config.h" #include "my_config.h"
#include "sys.h" #include "sys.h"
#ifndef NARROW_WRAPPER
#define WIDECHAR
#endif
This diff is collapsed.
/* $NetBSD: el.h,v 1.17 2006/12/15 22:13:33 christos Exp $ */ /* $NetBSD: el.h,v 1.25 2011/07/29 23:44:44 christos Exp $ */
/*- /*-
* Copyright (c) 1992, 1993 * Copyright (c) 1992, 1993
...@@ -46,15 +46,21 @@ ...@@ -46,15 +46,21 @@
#define VIDEFAULT #define VIDEFAULT
#define ANCHOR #define ANCHOR
#include "histedit.h"
#include "chartype.h"
#include <stdio.h> #include <stdio.h>
#include <sys/types.h> #include <sys/types.h>
#define EL_BUFSIZ 1024 /* Maximum line size */ #define EL_BUFSIZ ((size_t)4096) /* Maximum line size */
#define HANDLE_SIGNALS 0x01 #define HANDLE_SIGNALS 0x01
#define NO_TTY 0x02 #define NO_TTY 0x02
#define EDIT_DISABLED 0x04 #define EDIT_DISABLED 0x04
#define UNBUFFERED 0x08 #define UNBUFFERED 0x08
#define CHARSET_IS_MULTIBYTE 0x10
#define IGNORE_EXTCHARS 0x20 /* Ignore characters read > 0xff */
#define NARROW_HISTORY 0x40
#define NARROW_READ 0x80
typedef int bool_t; /* True or not */ typedef int bool_t; /* True or not */
...@@ -66,10 +72,10 @@ typedef struct coord_t { /* Position on the screen */ ...@@ -66,10 +72,10 @@ typedef struct coord_t { /* Position on the screen */
} coord_t; } coord_t;
typedef struct el_line_t { typedef struct el_line_t {
char *buffer; /* Input line */ Char *buffer; /* Input line */
char *cursor; /* Cursor position */ Char *cursor; /* Cursor position */
char *lastchar; /* Last character */ Char *lastchar; /* Last character */
const char *limit; /* Max position */ const Char *limit; /* Max position */
} el_line_t; } el_line_t;
/* /*
...@@ -82,21 +88,20 @@ typedef struct el_state_t { ...@@ -82,21 +88,20 @@ typedef struct el_state_t {
int metanext; /* Is the next char a meta char */ int metanext; /* Is the next char a meta char */
el_action_t lastcmd; /* Previous command */ el_action_t lastcmd; /* Previous command */
el_action_t thiscmd; /* this command */ el_action_t thiscmd; /* this command */
char thisch; /* char that generated it */ Char thisch; /* char that generated it */
} el_state_t; } el_state_t;
/* /*
* Until we come up with something better... * Until we come up with something better...
*/ */
#define el_strdup(a) strdup(a)
#define el_malloc(a) malloc(a) #define el_malloc(a) malloc(a)
#define el_realloc(a,b) realloc(a, b) #define el_realloc(a,b) realloc(a, b)
#define el_free(a) free(a) #define el_free(a) free(a)
#include "tty.h" #include "tty.h"
#include "prompt.h" #include "prompt.h"
#include "key.h" #include "keymacro.h"
#include "el_term.h" #include "el_terminal.h"
#include "refresh.h" #include "refresh.h"
#include "chared.h" #include "chared.h"
#include "common.h" #include "common.h"
...@@ -109,33 +114,41 @@ typedef struct el_state_t { ...@@ -109,33 +114,41 @@ typedef struct el_state_t {
#include "read.h" #include "read.h"
struct editline { struct editline {
char *el_prog; /* the program name */ Char *el_prog; /* the program name */
FILE *el_infile; /* Stdio stuff */ FILE *el_infile; /* Stdio stuff */
FILE *el_outfile; /* Stdio stuff */ FILE *el_outfile; /* Stdio stuff */
FILE *el_errfile; /* Stdio stuff */ FILE *el_errfile; /* Stdio stuff */
int el_infd; /* Input file descriptor */ int el_infd; /* Input file descriptor */
int el_outfd; /* Output file descriptor */
int el_errfd; /* Error file descriptor */
int el_flags; /* Various flags. */ int el_flags; /* Various flags. */
int el_errno; /* Local copy of errno */
coord_t el_cursor; /* Cursor location */ coord_t el_cursor; /* Cursor location */
char **el_display; /* Real screen image = what is there */ Char **el_display; /* Real screen image = what is there */
char **el_vdisplay; /* Virtual screen image = what we see */ Char **el_vdisplay; /* Virtual screen image = what we see */
void *el_data; /* Client data */ void *el_data; /* Client data */
el_line_t el_line; /* The current line information */ el_line_t el_line; /* The current line information */
el_state_t el_state; /* Current editor state */ el_state_t el_state; /* Current editor state */
el_term_t el_term; /* Terminal dependent stuff */ el_terminal_t el_terminal; /* Terminal dependent stuff */
el_tty_t el_tty; /* Tty dependent stuff */ el_tty_t el_tty; /* Tty dependent stuff */
el_refresh_t el_refresh; /* Refresh stuff */ el_refresh_t el_refresh; /* Refresh stuff */
el_prompt_t el_prompt; /* Prompt stuff */ el_prompt_t el_prompt; /* Prompt stuff */
el_prompt_t el_rprompt; /* Prompt stuff */ el_prompt_t el_rprompt; /* Prompt stuff */
el_chared_t el_chared; /* Characted editor stuff */ el_chared_t el_chared; /* Characted editor stuff */
el_map_t el_map; /* Key mapping stuff */ el_map_t el_map; /* Key mapping stuff */
el_key_t el_key; /* Key binding stuff */ el_keymacro_t el_keymacro; /* Key binding stuff */
el_history_t el_history; /* History stuff */ el_history_t el_history; /* History stuff */
el_search_t el_search; /* Search stuff */ el_search_t el_search; /* Search stuff */
el_signal_t el_signal; /* Signal handling stuff */ el_signal_t el_signal; /* Signal handling stuff */
el_read_t el_read; /* Character reading stuff */ el_read_t el_read; /* Character reading stuff */
#ifdef WIDECHAR
ct_buffer_t el_scratch; /* Scratch conversion buffer */
ct_buffer_t el_lgcyconv; /* Buffer for legacy wrappers */
LineInfo el_lgcylinfo; /* Legacy LineInfo buffer */
#endif
}; };
protected int el_editmode(EditLine *, int, const char **); protected int el_editmode(EditLine *, int, const Char **);
/* XXXMYSQL: Bug#23097 mysql can't insert korean on mysql prompt. */ /* XXXMYSQL: Bug#23097 mysql can't insert korean on mysql prompt. */
#define el_isprint(x) ((unsigned char) (x) < 0x80 ? isprint(x) : 1) #define el_isprint(x) ((unsigned char) (x) < 0x80 ? isprint(x) : 1)
......
/* $NetBSD: term.h,v 1.19 2008/09/10 15:45:37 christos Exp $ */ /* $NetBSD: terminal.h,v 1.3 2011/07/29 23:44:45 christos Exp $ */
/*- /*-
* Copyright (c) 1992, 1993 * Copyright (c) 1992, 1993
...@@ -37,17 +37,17 @@ ...@@ -37,17 +37,17 @@
/* /*
* el.term.h: Termcap header * el.term.h: Termcap header
*/ */
#ifndef _h_el_term #ifndef _h_el_terminal
#define _h_el_term #define _h_el_terminal
#include "histedit.h" #include "histedit.h"
typedef struct { /* Symbolic function key bindings */ typedef struct { /* Symbolic function key bindings */
const char *name; /* name of the key */ const Char *name; /* name of the key */
int key; /* Index in termcap table */ int key; /* Index in termcap table */
key_value_t fun; /* Function bound to it */ keymacro_value_t fun; /* Function bound to it */
int type; /* Type of function */ int type; /* Type of function */
} fkey_t; } funckey_t;
typedef struct { typedef struct {
const char *t_name; /* the terminal name */ const char *t_name; /* the terminal name */
...@@ -63,12 +63,12 @@ typedef struct { ...@@ -63,12 +63,12 @@ typedef struct {
#define TERM_HAS_AUTO_MARGINS 0x080 /* Has auto margins */ #define TERM_HAS_AUTO_MARGINS 0x080 /* Has auto margins */
#define TERM_HAS_MAGIC_MARGINS 0x100 /* Has magic margins */ #define TERM_HAS_MAGIC_MARGINS 0x100 /* Has magic margins */
char *t_buf; /* Termcap buffer */ char *t_buf; /* Termcap buffer */
int t_loc; /* location used */ size_t t_loc; /* location used */
char **t_str; /* termcap strings */ char **t_str; /* termcap strings */
int *t_val; /* termcap values */ int *t_val; /* termcap values */
char *t_cap; /* Termcap buffer */ char *t_cap; /* Termcap buffer */
fkey_t *t_fkey; /* Array of keys */ funckey_t *t_fkey; /* Array of keys */
} el_term_t; } el_terminal_t;
/* /*
* fKey indexes * fKey indexes
...@@ -81,36 +81,36 @@ typedef struct { ...@@ -81,36 +81,36 @@ typedef struct {
#define A_K_EN 5 #define A_K_EN 5
#define A_K_NKEYS 6 #define A_K_NKEYS 6
protected void term_move_to_line(EditLine *, int); protected void terminal_move_to_line(EditLine *, int);
protected void term_move_to_char(EditLine *, int); protected void terminal_move_to_char(EditLine *, int);
protected void term_clear_EOL(EditLine *, int); protected void terminal_clear_EOL(EditLine *, int);
protected void term_overwrite(EditLine *, const char *, int); protected void terminal_overwrite(EditLine *, const Char *, size_t);
protected void term_insertwrite(EditLine *, char *, int); protected void terminal_insertwrite(EditLine *, Char *, int);
protected void term_deletechars(EditLine *, int); protected void terminal_deletechars(EditLine *, int);
protected void term_clear_screen(EditLine *); protected void terminal_clear_screen(EditLine *);
protected void term_beep(EditLine *); protected void terminal_beep(EditLine *);
protected int term_change_size(EditLine *, int, int); protected int terminal_change_size(EditLine *, int, int);
protected int term_get_size(EditLine *, int *, int *); protected int terminal_get_size(EditLine *, int *, int *);
protected int term_init(EditLine *); protected int terminal_init(EditLine *);
protected void term_bind_arrow(EditLine *); protected void terminal_bind_arrow(EditLine *);
protected void term_print_arrow(EditLine *, const char *); protected void terminal_print_arrow(EditLine *, const Char *);
protected int term_clear_arrow(EditLine *, const char *); protected int terminal_clear_arrow(EditLine *, const Char *);
protected int term_set_arrow(EditLine *, const char *, key_value_t *, int); protected int terminal_set_arrow(EditLine *, const Char *, keymacro_value_t *, int);
protected void term_end(EditLine *); protected void terminal_end(EditLine *);
protected void term_get(EditLine *, const char **); protected void terminal_get(EditLine *, const char **);
protected int term_set(EditLine *, const char *); protected int terminal_set(EditLine *, const char *);
protected int term_settc(EditLine *, int, const char **); protected int terminal_settc(EditLine *, int, const Char **);
protected int term_gettc(EditLine *, int, char **); protected int terminal_gettc(EditLine *, int, char **);
protected int term_telltc(EditLine *, int, const char **); protected int terminal_telltc(EditLine *, int, const Char **);
protected int term_echotc(EditLine *, int, const char **); protected int terminal_echotc(EditLine *, int, const Char **);
protected void term_writec(EditLine *, int); protected void terminal_writec(EditLine *, Int);
protected int term__putc(EditLine *, int); protected int terminal__putc(EditLine *, Int);
protected void term__flush(EditLine *); protected void terminal__flush(EditLine *);
/* /*
* Easy access macros * Easy access macros
*/ */
#define EL_FLAGS (el)->el_term.t_flags #define EL_FLAGS (el)->el_terminal.t_flags
#define EL_CAN_INSERT (EL_FLAGS & TERM_CAN_INSERT) #define EL_CAN_INSERT (EL_FLAGS & TERM_CAN_INSERT)
#define EL_CAN_DELETE (EL_FLAGS & TERM_CAN_DELETE) #define EL_CAN_DELETE (EL_FLAGS & TERM_CAN_DELETE)
...@@ -122,4 +122,4 @@ protected void term__flush(EditLine *); ...@@ -122,4 +122,4 @@ protected void term__flush(EditLine *);
#define EL_HAS_AUTO_MARGINS (EL_FLAGS & TERM_HAS_AUTO_MARGINS) #define EL_HAS_AUTO_MARGINS (EL_FLAGS & TERM_HAS_AUTO_MARGINS)
#define EL_HAS_MAGIC_MARGINS (EL_FLAGS & TERM_HAS_MAGIC_MARGINS) #define EL_HAS_MAGIC_MARGINS (EL_FLAGS & TERM_HAS_MAGIC_MARGINS)
#endif /* _h_el_term */ #endif /* _h_el_terminal */
/* $NetBSD: eln.c,v 1.13 2011/08/16 16:25:15 christos Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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)
#endif /* not lint && not SCCSID */
#include "histedit.h"
#include "el.h"
#include "read.h"
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
public int
el_getc(EditLine *el, char *cp)
{
int num_read;
wchar_t wc = 0;
num_read = el_wgetc (el, &wc);
if (num_read > 0)
*cp = (char)wc;
return num_read;
}
public void
el_push(EditLine *el, const char *str)
{
/* Using multibyte->wide string decoding works fine under single-byte
* character sets too, and Does The Right Thing. */
el_wpush(el, ct_decode_string(str, &el->el_lgcyconv));
}
public const char *
el_gets(EditLine *el, int *nread)
{
const wchar_t *tmp;
tmp = el_wgets(el, nread);
return ct_encode_string(tmp, &el->el_lgcyconv);
}
public int
el_parse(EditLine *el, int argc, const char *argv[])
{
int ret;
const wchar_t **wargv;
wargv = (const wchar_t **)
ct_decode_argv(argc, argv, &el->el_lgcyconv);
if (!wargv)
return -1;
ret = el_wparse(el, argc, wargv);
ct_free_argv(wargv);
return ret;
}
public int
el_set(EditLine *el, int op, ...)
{
va_list ap;
int ret;
if (!el)
return -1;
va_start(ap, op);
switch (op) {
case EL_PROMPT: /* el_pfunc_t */
case EL_RPROMPT: {
el_pfunc_t p = va_arg(ap, el_pfunc_t);
ret = prompt_set(el, p, 0, op, 0);
break;
}
case EL_RESIZE: {
el_zfunc_t p = va_arg(ap, el_zfunc_t);
void *arg = va_arg(ap, void *);
ret = ch_resizefun(el, p, arg);
break;
}
case EL_TERMINAL: /* const char * */
ret = el_wset(el, op, va_arg(ap, char *));
break;
case EL_EDITOR: /* const wchar_t * */
ret = el_wset(el, op, ct_decode_string(va_arg(ap, char *),
&el->el_lgcyconv));
break;
case EL_SIGNAL: /* int */
case EL_EDITMODE:
case EL_UNBUFFERED:
case EL_PREP_TERM:
ret = el_wset(el, op, va_arg(ap, int));
break;
case EL_BIND: /* const char * list -> const wchar_t * list */
case EL_TELLTC:
case EL_SETTC:
case EL_ECHOTC:
case EL_SETTY: {
const char *argv[20];
int i;
const wchar_t **wargv;
for (i = 1; i < (int)__arraycount(argv); ++i)
if ((argv[i] = va_arg(ap, char *)) == NULL)
break;
argv[0] = NULL;
wargv = (const wchar_t **)
ct_decode_argv(i, argv, &el->el_lgcyconv);
if (!wargv) {
ret = -1;
goto out;
}
/*
* AFAIK we can't portably pass through our new wargv to
* el_wset(), so we have to reimplement the body of
* el_wset() for these ops.
*/
switch (op) {
case EL_BIND:
wargv[0] = STR("bind");
ret = map_bind(el, i, wargv);
break;
case EL_TELLTC:
wargv[0] = STR("telltc");
ret = terminal_telltc(el, i, wargv);
break;
case EL_SETTC:
wargv[0] = STR("settc");
ret = terminal_settc(el, i, wargv);
break;
case EL_ECHOTC:
wargv[0] = STR("echotc");
ret = terminal_echotc(el, i, wargv);
break;
case EL_SETTY:
wargv[0] = STR("setty");
ret = tty_stty(el, i, wargv);
break;
default:
ret = -1;
}
ct_free_argv(wargv);
break;
}
/* XXX: do we need to change el_func_t too? */
case EL_ADDFN: { /* const char *, const char *, el_func_t */
const char *args[2];
el_func_t func;
wchar_t **wargv;
args[0] = va_arg(ap, const char *);
args[1] = va_arg(ap, const char *);
func = va_arg(ap, el_func_t);
wargv = ct_decode_argv(2, args, &el->el_lgcyconv);
if (!wargv) {
ret = -1;
goto out;
}
// XXX: The two strdup's leak
ret = map_addfunc(el, Strdup(wargv[0]), Strdup(wargv[1]),
func);
ct_free_argv(wargv);
break;
}
case EL_HIST: { /* hist_fun_t, const char * */
hist_fun_t fun = va_arg(ap, hist_fun_t);
void *ptr = va_arg(ap, void *);
ret = hist_set(el, fun, ptr);
el->el_flags |= NARROW_HISTORY;
break;
}
/* XXX: do we need to change el_rfunc_t? */
case EL_GETCFN: /* el_rfunc_t */
ret = el_wset(el, op, va_arg(ap, el_rfunc_t));
el->el_flags |= NARROW_READ;
break;
case EL_CLIENTDATA: /* void * */
ret = el_wset(el, op, va_arg(ap, void *));
break;
case EL_SETFP: { /* int, FILE * */
int what = va_arg(ap, int);
FILE *fp = va_arg(ap, FILE *);
ret = el_wset(el, op, what, fp);
break;
}
case EL_PROMPT_ESC: /* el_pfunc_t, char */
case EL_RPROMPT_ESC: {
el_pfunc_t p = va_arg(ap, el_pfunc_t);
char c = (char)va_arg(ap, int);
ret = prompt_set(el, p, c, op, 0);
break;
}
default:
ret = -1;
break;
}
out:
va_end(ap);
return ret;
}
public int
el_get(EditLine *el, int op, ...)
{
va_list ap;
int ret;
if (!el)
return -1;
va_start(ap, op);
switch (op) {
case EL_PROMPT: /* el_pfunc_t * */
case EL_RPROMPT: {
el_pfunc_t *p = va_arg(ap, el_pfunc_t *);
ret = prompt_get(el, p, 0, op);
break;
}
case EL_PROMPT_ESC: /* el_pfunc_t *, char **/
case EL_RPROMPT_ESC: {
el_pfunc_t *p = va_arg(ap, el_pfunc_t *);
char *c = va_arg(ap, char *);
wchar_t wc = 0;
ret = prompt_get(el, p, &wc, op);
*c = (char)wc;
break;
}
case EL_EDITOR: {
const char **p = va_arg(ap, const char **);
const wchar_t *pw;
ret = el_wget(el, op, &pw);
*p = ct_encode_string(pw, &el->el_lgcyconv);
if (!el->el_lgcyconv.csize)
ret = -1;
break;
}
case EL_TERMINAL: /* const char ** */
ret = el_wget(el, op, va_arg(ap, const char **));
break;
case EL_SIGNAL: /* int * */
case EL_EDITMODE:
case EL_UNBUFFERED:
case EL_PREP_TERM:
ret = el_wget(el, op, va_arg(ap, int *));
break;
case EL_GETTC: {
char *argv[20];
static char gettc[] = "gettc";
int i;
for (i = 1; i < (int)__arraycount(argv); ++i)
if ((argv[i] = va_arg(ap, char *)) == NULL)
break;
argv[0] = gettc;
ret = terminal_gettc(el, i, argv);
break;
}
/* XXX: do we need to change el_rfunc_t? */
case EL_GETCFN: /* el_rfunc_t */
ret = el_wget(el, op, va_arg(ap, el_rfunc_t *));
break;
case EL_CLIENTDATA: /* void ** */
ret = el_wget(el, op, va_arg(ap, void **));
break;
case EL_GETFP: { /* int, FILE ** */
int what = va_arg(ap, int);
FILE **fpp = va_arg(ap, FILE **);
ret = el_wget(el, op, what, fpp);
break;
}
default:
ret = -1;
break;
}
va_end(ap);
return ret;
}
const LineInfo *
el_line(EditLine *el)
{
const LineInfoW *winfo = el_wline(el);
LineInfo *info = &el->el_lgcylinfo;
size_t offset;
const Char *p;
info->buffer = ct_encode_string(winfo->buffer, &el->el_lgcyconv);
offset = 0;
for (p = winfo->buffer; p < winfo->cursor; p++)
offset += ct_enc_width(*p);
info->cursor = info->buffer + offset;
offset = 0;
for (p = winfo->buffer; p < winfo->lastchar; p++)
offset += ct_enc_width(*p);
info->lastchar = info->buffer + offset;
return info;
}
int
el_insertstr(EditLine *el, const char *str)
{
return el_winsertstr(el, ct_decode_string(str, &el->el_lgcyconv));
}
This diff is collapsed.
This diff is collapsed.
/* $NetBSD: filecomplete.h,v 1.6 2008/04/29 06:53:01 martin Exp $ */ /* $NetBSD: filecomplete.h,v 1.9 2009/12/30 22:37:40 christos Exp $ */
/*- /*-
* Copyright (c) 1997 The NetBSD Foundation, Inc. * Copyright (c) 1997 The NetBSD Foundation, Inc.
...@@ -34,10 +34,10 @@ ...@@ -34,10 +34,10 @@
int fn_complete(EditLine *, int fn_complete(EditLine *,
char *(*)(const char *, int), char *(*)(const char *, int),
char **(*)(const char *, int, int), char **(*)(const char *, int, int),
const char *, const char *, const char *(*)(const char *), int, const Char *, const Char *, const char *(*)(const char *), size_t,
int *, int *, int *, int *); int *, int *, int *, int *);
void fn_display_match_list(EditLine *, char **, int, int); void fn_display_match_list(EditLine *, char **, size_t, size_t);
char *fn_tilde_expand(const char *); char *fn_tilde_expand(const char *);
char *fn_filename_completion_function(const char *, int); char *fn_filename_completion_function(const char *, int);
......
/* $NetBSD: hist.c,v 1.15 2003/11/01 23:36:39 christos Exp $ */ /* $NetBSD: hist.c,v 1.20 2011/07/29 15:16:33 christos Exp $ */
/*- /*-
* Copyright (c) 1992, 1993 * Copyright (c) 1992, 1993
...@@ -55,12 +55,12 @@ hist_init(EditLine *el) ...@@ -55,12 +55,12 @@ hist_init(EditLine *el)
el->el_history.fun = NULL; el->el_history.fun = NULL;
el->el_history.ref = NULL; el->el_history.ref = NULL;
el->el_history.buf = (char *) el_malloc(EL_BUFSIZ); el->el_history.buf = el_malloc(EL_BUFSIZ * sizeof(*el->el_history.buf));
el->el_history.sz = EL_BUFSIZ; el->el_history.sz = EL_BUFSIZ;
if (el->el_history.buf == NULL) if (el->el_history.buf == NULL)
return (-1); return -1;
el->el_history.last = el->el_history.buf; el->el_history.last = el->el_history.buf;
return (0); return 0;
} }
...@@ -71,7 +71,7 @@ protected void ...@@ -71,7 +71,7 @@ protected void
hist_end(EditLine *el) hist_end(EditLine *el)
{ {
el_free((ptr_t) el->el_history.buf); el_free(el->el_history.buf);
el->el_history.buf = NULL; el->el_history.buf = NULL;
} }
...@@ -80,12 +80,12 @@ hist_end(EditLine *el) ...@@ -80,12 +80,12 @@ hist_end(EditLine *el)
* Set new history interface * Set new history interface
*/ */
protected int protected int
hist_set(EditLine *el, hist_fun_t fun, ptr_t ptr) hist_set(EditLine *el, hist_fun_t fun, void *ptr)
{ {
el->el_history.ref = ptr; el->el_history.ref = ptr;
el->el_history.fun = fun; el->el_history.fun = fun;
return (0); return 0;
} }
...@@ -96,11 +96,11 @@ hist_set(EditLine *el, hist_fun_t fun, ptr_t ptr) ...@@ -96,11 +96,11 @@ hist_set(EditLine *el, hist_fun_t fun, ptr_t ptr)
protected el_action_t protected el_action_t
hist_get(EditLine *el) hist_get(EditLine *el)
{ {
const char *hp; const Char *hp;
int h; int h;
if (el->el_history.eventno == 0) { /* if really the current line */ if (el->el_history.eventno == 0) { /* if really the current line */
(void) strncpy(el->el_line.buffer, el->el_history.buf, (void) Strncpy(el->el_line.buffer, el->el_history.buf,
el->el_history.sz); el->el_history.sz);
el->el_line.lastchar = el->el_line.buffer + el->el_line.lastchar = el->el_line.buffer +
(el->el_history.last - el->el_history.buf); (el->el_history.last - el->el_history.buf);
...@@ -112,24 +112,25 @@ hist_get(EditLine *el) ...@@ -112,24 +112,25 @@ hist_get(EditLine *el)
#endif /* KSHVI */ #endif /* KSHVI */
el->el_line.cursor = el->el_line.lastchar; el->el_line.cursor = el->el_line.lastchar;
return (CC_REFRESH); return CC_REFRESH;
} }
if (el->el_history.ref == NULL) if (el->el_history.ref == NULL)
return (CC_ERROR); return CC_ERROR;
hp = HIST_FIRST(el); hp = HIST_FIRST(el);
if (hp == NULL) if (hp == NULL)
return (CC_ERROR); return CC_ERROR;
for (h = 1; h < el->el_history.eventno; h++) for (h = 1; h < el->el_history.eventno; h++)
if ((hp = HIST_NEXT(el)) == NULL) { if ((hp = HIST_NEXT(el)) == NULL) {
el->el_history.eventno = h; el->el_history.eventno = h;
return (CC_ERROR); return CC_ERROR;
} }
(void) strlcpy(el->el_line.buffer, hp, (void) Strncpy(el->el_line.buffer, hp,
(size_t)(el->el_line.limit - el->el_line.buffer)); (size_t)(el->el_line.limit - el->el_line.buffer));
el->el_line.lastchar = el->el_line.buffer + strlen(el->el_line.buffer); el->el_line.buffer[el->el_line.limit - el->el_line.buffer - 1] = '\0';
el->el_line.lastchar = el->el_line.buffer + Strlen(el->el_line.buffer);
if (el->el_line.lastchar > el->el_line.buffer if (el->el_line.lastchar > el->el_line.buffer
&& el->el_line.lastchar[-1] == '\n') && el->el_line.lastchar[-1] == '\n')
...@@ -144,7 +145,7 @@ hist_get(EditLine *el) ...@@ -144,7 +145,7 @@ hist_get(EditLine *el)
#endif /* KSHVI */ #endif /* KSHVI */
el->el_line.cursor = el->el_line.lastchar; el->el_line.cursor = el->el_line.lastchar;
return (CC_REFRESH); return CC_REFRESH;
} }
...@@ -152,34 +153,34 @@ hist_get(EditLine *el) ...@@ -152,34 +153,34 @@ hist_get(EditLine *el)
* process a history command * process a history command
*/ */
protected int protected int
hist_command(EditLine *el, int argc, const char **argv) hist_command(EditLine *el, int argc, const Char **argv)
{ {
const char *str; const Char *str;
int num; int num;
HistEvent ev; TYPE(HistEvent) ev;
if (el->el_history.ref == NULL) if (el->el_history.ref == NULL)
return (-1); return -1;
if (argc == 1 || strcmp(argv[1], "list") == 0) { if (argc == 1 || Strcmp(argv[1], STR("list")) == 0) {
/* List history entries */ /* List history entries */
for (str = HIST_LAST(el); str != NULL; str = HIST_PREV(el)) for (str = HIST_LAST(el); str != NULL; str = HIST_PREV(el))
(void) fprintf(el->el_outfile, "%d %s", (void) fprintf(el->el_outfile, "%d %s",
el->el_history.ev.num, str); el->el_history.ev.num, ct_encode_string(str, &el->el_scratch));
return (0); return 0;
} }
if (argc != 3) if (argc != 3)
return (-1); return -1;
num = (int)strtol(argv[2], NULL, 0); num = (int)Strtol(argv[2], NULL, 0);
if (strcmp(argv[1], "size") == 0) if (Strcmp(argv[1], STR("size")) == 0)
return history(el->el_history.ref, &ev, H_SETSIZE, num); return FUNW(history)(el->el_history.ref, &ev, H_SETSIZE, num);
if (strcmp(argv[1], "unique") == 0) if (Strcmp(argv[1], STR("unique")) == 0)
return history(el->el_history.ref, &ev, H_SETUNIQUE, num); return FUNW(history)(el->el_history.ref, &ev, H_SETUNIQUE, num);
return -1; return -1;
} }
...@@ -192,13 +193,13 @@ protected int ...@@ -192,13 +193,13 @@ protected int
/*ARGSUSED*/ /*ARGSUSED*/
hist_enlargebuf(EditLine *el, size_t oldsz, size_t newsz) hist_enlargebuf(EditLine *el, size_t oldsz, size_t newsz)
{ {
char *newbuf; Char *newbuf;
newbuf = realloc(el->el_history.buf, newsz); newbuf = el_realloc(el->el_history.buf, newsz * sizeof(*newbuf));
if (!newbuf) if (!newbuf)
return 0; return 0;
(void) memset(&newbuf[oldsz], '\0', newsz - oldsz); (void) memset(&newbuf[oldsz], '\0', (newsz - oldsz) * sizeof(*newbuf));
el->el_history.last = newbuf + el->el_history.last = newbuf +
(el->el_history.last - el->el_history.buf); (el->el_history.last - el->el_history.buf);
...@@ -207,3 +208,15 @@ hist_enlargebuf(EditLine *el, size_t oldsz, size_t newsz) ...@@ -207,3 +208,15 @@ hist_enlargebuf(EditLine *el, size_t oldsz, size_t newsz)
return 1; return 1;
} }
#ifdef WIDECHAR
protected wchar_t *
hist_convert(EditLine *el, int fn, void *arg)
{
HistEventW ev;
if ((*(el)->el_history.fun)((el)->el_history.ref, &ev, fn, arg) == -1)
return NULL;
return ct_decode_string((const char *)(const void *)ev.str,
&el->el_scratch);
}
#endif
/* $NetBSD: hist.h,v 1.10 2003/08/07 16:44:31 agc Exp $ */ /* $NetBSD: hist.h,v 1.13 2011/07/28 20:50:55 christos Exp $ */
/*- /*-
* Copyright (c) 1992, 1993 * Copyright (c) 1992, 1993
...@@ -42,21 +42,29 @@ ...@@ -42,21 +42,29 @@
#include "histedit.h" #include "histedit.h"
typedef int (*hist_fun_t)(ptr_t, HistEvent *, int, ...); typedef int (*hist_fun_t)(void *, TYPE(HistEvent) *, int, ...);
typedef struct el_history_t { typedef struct el_history_t {
char *buf; /* The history buffer */ Char *buf; /* The history buffer */
size_t sz; /* Size of history buffer */ size_t sz; /* Size of history buffer */
char *last; /* The last character */ Char *last; /* The last character */
int eventno; /* Event we are looking for */ int eventno; /* Event we are looking for */
ptr_t ref; /* Argument for history fcns */ void * ref; /* Argument for history fcns */
hist_fun_t fun; /* Event access */ hist_fun_t fun; /* Event access */
HistEvent ev; /* Event cookie */ TYPE(HistEvent) ev; /* Event cookie */
} el_history_t; } el_history_t;
#define HIST_FUN(el, fn, arg) \ #define HIST_FUN_INTERNAL(el, fn, arg) \
((((*(el)->el_history.fun) ((el)->el_history.ref, &(el)->el_history.ev, \ ((((*(el)->el_history.fun) ((el)->el_history.ref, &(el)->el_history.ev, \
fn, arg)) == -1) ? NULL : (el)->el_history.ev.str) fn, arg)) == -1) ? NULL : (el)->el_history.ev.str)
#ifdef WIDECHAR
#define HIST_FUN(el, fn, arg) \
(((el)->el_flags & NARROW_HISTORY) ? hist_convert(el, fn, arg) : \
HIST_FUN_INTERNAL(el, fn, arg))
#else
#define HIST_FUN(el, fn, arg) HIST_FUN_INTERNAL(el, fn, arg)
#endif
#define HIST_NEXT(el) HIST_FUN(el, H_NEXT, NULL) #define HIST_NEXT(el) HIST_FUN(el, H_NEXT, NULL)
#define HIST_FIRST(el) HIST_FUN(el, H_FIRST, NULL) #define HIST_FIRST(el) HIST_FUN(el, H_FIRST, NULL)
...@@ -69,8 +77,11 @@ typedef struct el_history_t { ...@@ -69,8 +77,11 @@ typedef struct el_history_t {
protected int hist_init(EditLine *); protected int hist_init(EditLine *);
protected void hist_end(EditLine *); protected void hist_end(EditLine *);
protected el_action_t hist_get(EditLine *); protected el_action_t hist_get(EditLine *);
protected int hist_set(EditLine *, hist_fun_t, ptr_t); protected int hist_set(EditLine *, hist_fun_t, void *);
protected int hist_command(EditLine *, int, const char **); protected int hist_command(EditLine *, int, const Char **);
protected int hist_enlargebuf(EditLine *, size_t, size_t); protected int hist_enlargebuf(EditLine *, size_t, size_t);
#ifdef WIDECHAR
protected wchar_t *hist_convert(EditLine *, int, void *);
#endif
#endif /* _h_el_hist */ #endif /* _h_el_hist */
/* $NetBSD: histedit.h,v 1.35 2009/02/05 19:15:44 christos Exp $ */ /* $NetBSD: histedit.h,v 1.48 2011/07/28 20:50:55 christos Exp $ */
/*- /*-
* Copyright (c) 1992, 1993 * Copyright (c) 1992, 1993
...@@ -43,6 +43,8 @@ ...@@ -43,6 +43,8 @@
#define LIBEDIT_MAJOR 2 #define LIBEDIT_MAJOR 2
#define LIBEDIT_MINOR 11 #define LIBEDIT_MINOR 11
#include <stdint.h>
#include <sys/types.h> #include <sys/types.h>
#include <stdio.h> #include <stdio.h>
...@@ -114,29 +116,46 @@ unsigned char _el_fn_complete(EditLine *, int); ...@@ -114,29 +116,46 @@ unsigned char _el_fn_complete(EditLine *, int);
/* /*
* el_set/el_get parameters * el_set/el_get parameters
*
* When using el_wset/el_wget (as opposed to el_set/el_get):
* Char is wchar_t, otherwise it is char.
* prompt_func is el_wpfunc_t, otherwise it is el_pfunc_t .
* Prompt function prototypes are:
* typedef char *(*el_pfunct_t) (EditLine *);
* typedef wchar_t *(*el_wpfunct_t) (EditLine *);
*
* For operations that support set or set/get, the argument types listed are for
* the "set" operation. For "get", each listed type must be a pointer.
* E.g. EL_EDITMODE takes an int when set, but an int* when get.
*
* Operations that only support "get" have the correct argument types listed.
*/ */
#define EL_PROMPT 0 /* , el_pfunc_t); */ #define EL_PROMPT 0 /* , prompt_func); set/get */
#define EL_TERMINAL 1 /* , const char *); */ #define EL_TERMINAL 1 /* , const char *); set/get */
#define EL_EDITOR 2 /* , const char *); */ #define EL_EDITOR 2 /* , const Char *); set/get */
#define EL_SIGNAL 3 /* , int); */ #define EL_SIGNAL 3 /* , int); set/get */
#define EL_BIND 4 /* , const char *, ..., NULL); */ #define EL_BIND 4 /* , const Char *, ..., NULL); set */
#define EL_TELLTC 5 /* , const char *, ..., NULL); */ #define EL_TELLTC 5 /* , const Char *, ..., NULL); set */
#define EL_SETTC 6 /* , const char *, ..., NULL); */ #define EL_SETTC 6 /* , const Char *, ..., NULL); set */
#define EL_ECHOTC 7 /* , const char *, ..., NULL); */ #define EL_ECHOTC 7 /* , const Char *, ..., NULL); set */
#define EL_SETTY 8 /* , const char *, ..., NULL); */ #define EL_SETTY 8 /* , const Char *, ..., NULL); set */
#define EL_ADDFN 9 /* , const char *, const char * */ #define EL_ADDFN 9 /* , const Char *, const Char, set */
/* , el_func_t); */ /* el_func_t); */
#define EL_HIST 10 /* , hist_fun_t, const char *); */ #define EL_HIST 10 /* , hist_fun_t, const void *); set */
#define EL_EDITMODE 11 /* , int); */ #define EL_EDITMODE 11 /* , int); set/get */
#define EL_RPROMPT 12 /* , el_pfunc_t); */ #define EL_RPROMPT 12 /* , prompt_func); set/get */
#define EL_GETCFN 13 /* , el_rfunc_t); */ #define EL_GETCFN 13 /* , el_rfunc_t); set/get */
#define EL_CLIENTDATA 14 /* , void *); */ #define EL_CLIENTDATA 14 /* , void *); set/get */
#define EL_UNBUFFERED 15 /* , int); */ #define EL_UNBUFFERED 15 /* , int); set/get */
#define EL_PREP_TERM 16 /* , int); */ #define EL_PREP_TERM 16 /* , int); set */
#define EL_GETTC 17 /* , const char *, ..., NULL); */ #define EL_GETTC 17 /* , const Char *, ..., NULL); get */
#define EL_GETFP 18 /* , int, FILE **); */ #define EL_GETFP 18 /* , int, FILE **); get */
#define EL_SETFP 19 /* , int, FILE *); */ #define EL_SETFP 19 /* , int, FILE *); set */
#define EL_REFRESH 20 /* , void); */ #define EL_REFRESH 20 /* , void); set */
#define EL_PROMPT_ESC 21 /* , prompt_func, Char); set/get */
#define EL_RPROMPT_ESC 22 /* , prompt_func, Char); set/get */
#define EL_RESIZE 23 /* , el_zfunc_t, void *); set */
#define EL_BUILTIN_GETCFN (NULL) #define EL_BUILTIN_GETCFN (NULL)
...@@ -188,12 +207,12 @@ int history(History *, HistEvent *, int, ...); ...@@ -188,12 +207,12 @@ int history(History *, HistEvent *, int, ...);
#define H_NEXT 6 /* , void); */ #define H_NEXT 6 /* , void); */
#define H_CURR 8 /* , const int); */ #define H_CURR 8 /* , const int); */
#define H_SET 7 /* , int); */ #define H_SET 7 /* , int); */
#define H_ADD 9 /* , const char *); */ #define H_ADD 9 /* , const wchar_t *); */
#define H_ENTER 10 /* , const char *); */ #define H_ENTER 10 /* , const wchar_t *); */
#define H_APPEND 11 /* , const char *); */ #define H_APPEND 11 /* , const wchar_t *); */
#define H_END 12 /* , void); */ #define H_END 12 /* , void); */
#define H_NEXT_STR 13 /* , const char *); */ #define H_NEXT_STR 13 /* , const wchar_t *); */
#define H_PREV_STR 14 /* , const char *); */ #define H_PREV_STR 14 /* , const wchar_t *); */
#define H_NEXT_EVENT 15 /* , const int); */ #define H_NEXT_EVENT 15 /* , const int); */
#define H_PREV_EVENT 16 /* , const int); */ #define H_PREV_EVENT 16 /* , const int); */
#define H_LOAD 17 /* , const char *); */ #define H_LOAD 17 /* , const char *); */
...@@ -202,6 +221,10 @@ int history(History *, HistEvent *, int, ...); ...@@ -202,6 +221,10 @@ int history(History *, HistEvent *, int, ...);
#define H_SETUNIQUE 20 /* , int); */ #define H_SETUNIQUE 20 /* , int); */
#define H_GETUNIQUE 21 /* , void); */ #define H_GETUNIQUE 21 /* , void); */
#define H_DEL 22 /* , int); */ #define H_DEL 22 /* , int); */
#define H_NEXT_EVDATA 23 /* , const int, histdata_t *); */
#define H_DELDATA 24 /* , int, histdata_t *);*/
#define H_REPLACE 25 /* , const char *, histdata_t); */
/* /*
...@@ -221,6 +244,74 @@ int tok_line(Tokenizer *, const LineInfo *, ...@@ -221,6 +244,74 @@ int tok_line(Tokenizer *, const LineInfo *,
int tok_str(Tokenizer *, const char *, int tok_str(Tokenizer *, const char *,
int *, const char ***); int *, const char ***);
/*
* Begin Wide Character Support
*/
#ifdef __linux__
/* Apparently we need _GNU_SOURCE defined to get access to wcsdup on Linux */
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#endif
#include <wchar.h>
#include <wctype.h>
/*
* Wide character versions
*/
/*
* ==== Editing ====
*/
typedef struct lineinfow {
const wchar_t *buffer;
const wchar_t *cursor;
const wchar_t *lastchar;
} LineInfoW;
const wchar_t *el_wgets(EditLine *, int *);
int el_wgetc(EditLine *, wchar_t *);
void el_wpush(EditLine *, const wchar_t *);
int el_wparse(EditLine *, int, const wchar_t **);
int el_wset(EditLine *, int, ...);
int el_wget(EditLine *, int, ...);
const LineInfoW *el_wline(EditLine *);
int el_winsertstr(EditLine *, const wchar_t *);
#define el_wdeletestr el_deletestr
/*
* ==== History ====
*/
typedef struct histeventW {
int num;
const wchar_t *str;
} HistEventW;
typedef struct historyW HistoryW;
HistoryW * history_winit(void);
void history_wend(HistoryW *);
int history_w(HistoryW *, HistEventW *, int, ...);
/*
* ==== Tokenization ====
*/
typedef struct tokenizerW TokenizerW;
/* Wide character tokenizer support */
TokenizerW *tok_winit(const wchar_t *);
void tok_wend(TokenizerW *);
void tok_wreset(TokenizerW *);
int tok_wline(TokenizerW *, const LineInfoW *,
int *, const wchar_t ***, int *, int *);
int tok_wstr(TokenizerW *, const wchar_t *,
int *, const wchar_t ***);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
This diff is collapsed.
#define NARROW_WRAPPER
#include "config.h"
#undef WIDECHAR
#define NARROWCHAR
#include "./history.c"
/* $NetBSD: key.h,v 1.10 2006/03/23 20:22:51 christos Exp $ */ /* $NetBSD: keymacro.h,v 1.2 2011/07/28 03:44:36 christos Exp $ */
/*- /*-
* Copyright (c) 1992, 1993 * Copyright (c) 1992, 1993
...@@ -35,47 +35,42 @@ ...@@ -35,47 +35,42 @@
*/ */
/* /*
* el.key.h: Key macro header * el.keymacro.h: Key macro header
*/ */
#ifndef _h_el_key #ifndef _h_el_keymacro
#define _h_el_key #define _h_el_keymacro
typedef union key_value_t { typedef union keymacro_value_t {
el_action_t cmd; /* If it is a command the # */ el_action_t cmd; /* If it is a command the # */
char *str; /* If it is a string... */ Char *str; /* If it is a string... */
} key_value_t; } keymacro_value_t;
typedef struct key_node_t key_node_t; typedef struct keymacro_node_t keymacro_node_t;
typedef struct el_key_t { typedef struct el_keymacromacro_t {
char *buf; /* Key print buffer */ Char *buf; /* Key print buffer */
key_node_t *map; /* Key map */ keymacro_node_t *map; /* Key map */
key_value_t val; /* Local conversion buffer */ keymacro_value_t val; /* Local conversion buffer */
} el_key_t; } el_keymacro_t;
#define XK_CMD 0 #define XK_CMD 0
#define XK_STR 1 #define XK_STR 1
#define XK_NOD 2 #define XK_NOD 2
#define XK_EXE 3 #define XK_EXE 3
#undef key_end protected int keymacro_init(EditLine *);
#undef key_clear protected void keymacro_end(EditLine *);
#undef key_print protected keymacro_value_t *keymacro_map_cmd(EditLine *, int);
protected keymacro_value_t *keymacro_map_str(EditLine *, Char *);
protected int key_init(EditLine *); protected void keymacro_reset(EditLine *);
protected void key_end(EditLine *); protected int keymacro_get(EditLine *, Char *, keymacro_value_t *);
protected key_value_t *key_map_cmd(EditLine *, int); protected void keymacro_add(EditLine *, const Char *, keymacro_value_t *, int);
protected key_value_t *key_map_str(EditLine *, char *); protected void keymacro_clear(EditLine *, el_action_t *, const Char *);
protected void key_reset(EditLine *); protected int keymacro_delete(EditLine *, const Char *);
protected int key_get(EditLine *, char *, key_value_t *); protected void keymacro_print(EditLine *, const Char *);
protected void key_add(EditLine *, const char *, key_value_t *, int); protected void keymacro_kprint(EditLine *, const Char *, keymacro_value_t *,
protected void key_clear(EditLine *, el_action_t *, const char *);
protected int key_delete(EditLine *, const char *);
protected void key_print(EditLine *, const char *);
protected void key_kprint(EditLine *, const char *, key_value_t *,
int); int);
protected int key__decode_str(const char *, char *, int, protected size_t keymacro__decode_str(const Char *, char *, size_t,
const char *); const char *);
protected int key__decode_char(char *, int, int, int);
#endif /* _h_el_key */ #endif /* _h_el_keymacro */
#!/bin/sh - #!/bin/sh -
# $NetBSD: makelist,v 1.11 2005/10/22 16:45:03 christos Exp $ # $NetBSD: makelist,v 1.16 2010/04/18 21:17:05 christos Exp $
# #
# Copyright (c) 1992, 1993 # Copyright (c) 1992, 1993
# The Regents of the University of California. All rights reserved. # The Regents of the University of California. All rights reserved.
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
# makelist.sh: Automatically generate header files... # makelist.sh: Automatically generate header files...
AWK=@AWK@ AWK=@AWK@
USAGE="Usage: $0 -h|-e|-fc|-fh|-bc|-bh|-m <filenames>" USAGE="Usage: $0 -n|-h|-e|-fc|-fh|-bc|-bh|-m <filenames>"
if [ "x$1" = "x" ] if [ "x$1" = "x" ]
then then
...@@ -53,6 +53,14 @@ case $FLAG in ...@@ -53,6 +53,14 @@ case $FLAG in
# generate foo.h file from foo.c # generate foo.h file from foo.c
# #
-n)
cat << _EOF
#undef WIDECHAR
#define NARROWCHAR
#include "${FILES}"
_EOF
;;
-h) -h)
set - `echo $FILES | sed -e 's/\\./_/g'` set - `echo $FILES | sed -e 's/\\./_/g'`
hdr="_h_`basename $1`" hdr="_h_`basename $1`"
...@@ -70,7 +78,7 @@ case $FLAG in ...@@ -70,7 +78,7 @@ case $FLAG in
# XXX: need a space between name and prototype so that -fc and -fh # XXX: need a space between name and prototype so that -fc and -fh
# parsing is much easier # parsing is much easier
# #
printf("protected el_action_t\t%s (EditLine *, int);\n", name); printf("protected el_action_t\t%s (EditLine *, Int);\n", name);
} }
} }
END { END {
...@@ -85,6 +93,7 @@ case $FLAG in ...@@ -85,6 +93,7 @@ case $FLAG in
BEGIN { BEGIN {
printf("/* Automatically generated file, do not edit */\n"); printf("/* Automatically generated file, do not edit */\n");
printf("#include \"config.h\"\n#include \"el.h\"\n"); printf("#include \"config.h\"\n#include \"el.h\"\n");
printf("#include \"chartype.h\"\n");
printf("private const struct el_bindings_t el_func_help[] = {\n"); printf("private const struct el_bindings_t el_func_help[] = {\n");
low = "abcdefghijklmnopqrstuvwxyz_"; low = "abcdefghijklmnopqrstuvwxyz_";
high = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_"; high = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_";
...@@ -106,18 +115,18 @@ case $FLAG in ...@@ -106,18 +115,18 @@ case $FLAG in
fname = fname s; fname = fname s;
} }
printf(" { %-30.30s %-30.30s\n","\"" fname "\",", uname ","); printf(" { %-30.30s %-30.30s\n","STR(\"" fname "\"),", uname ",");
ok = 1; ok = 1;
} }
} }
/^ \*/ { /^ \*/ {
if (ok) { if (ok) {
printf(" \""); printf(" STR(\"");
for (i = 2; i < NF; i++) for (i = 2; i < NF; i++)
printf("%s ", $i); printf("%s ", $i);
# XXXMYSQL: support CRLF # XXXMYSQL: support CRLF
sub("\r", "", $i); sub("\r", "", $i);
printf("%s\" },\n", $i); printf("%s\") },\n", $i);
ok = 0; ok = 0;
} }
} }
...@@ -157,7 +166,7 @@ case $FLAG in ...@@ -157,7 +166,7 @@ case $FLAG in
END { END {
printf("#define\t%-30.30s\t%3d\n", "EL_NUM_FCNS", count); printf("#define\t%-30.30s\t%3d\n", "EL_NUM_FCNS", count);
printf("typedef el_action_t (*el_func_t)(EditLine *, int);"); printf("typedef el_action_t (*el_func_t)(EditLine *, Int);");
printf("\nprotected const el_func_t* func__get(void);\n"); printf("\nprotected const el_func_t* func__get(void);\n");
printf("#endif /* _h_fcns_c */\n"); printf("#endif /* _h_fcns_c */\n");
}' }'
......
This diff is collapsed.
/* $NetBSD: map.h,v 1.8 2003/08/07 16:44:32 agc Exp $ */ /* $NetBSD: map.h,v 1.9 2009/12/30 22:37:40 christos Exp $ */
/*- /*-
* Copyright (c) 1992, 1993 * Copyright (c) 1992, 1993
...@@ -41,9 +41,9 @@ ...@@ -41,9 +41,9 @@
#define _h_el_map #define _h_el_map
typedef struct el_bindings_t { /* for the "bind" shell command */ typedef struct el_bindings_t { /* for the "bind" shell command */
const char *name; /* function name for bind command */ const Char *name; /* function name for bind command */
int func; /* function numeric value */ int func; /* function numeric value */
const char *description; /* description of function */ const Char *description; /* description of function */
} el_bindings_t; } el_bindings_t;
...@@ -63,13 +63,15 @@ typedef struct el_map_t { ...@@ -63,13 +63,15 @@ typedef struct el_map_t {
#define MAP_EMACS 0 #define MAP_EMACS 0
#define MAP_VI 1 #define MAP_VI 1
protected int map_bind(EditLine *, int, const char **); #define N_KEYS 256
protected int map_bind(EditLine *, int, const Char **);
protected int map_init(EditLine *); protected int map_init(EditLine *);
protected void map_end(EditLine *); protected void map_end(EditLine *);
protected void map_init_vi(EditLine *); protected void map_init_vi(EditLine *);
protected void map_init_emacs(EditLine *); protected void map_init_emacs(EditLine *);
protected int map_set_editor(EditLine *, char *); protected int map_set_editor(EditLine *, Char *);
protected int map_get_editor(EditLine *, const char **); protected int map_get_editor(EditLine *, const Char **);
protected int map_addfunc(EditLine *, const char *, const char *, el_func_t); protected int map_addfunc(EditLine *, const Char *, const Char *, el_func_t);
#endif /* _h_el_map */ #endif /* _h_el_map */
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "config.h" #include "config.h"
#endif #endif
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint) #if defined(LIBC_SCCS) && !defined(lint)
#endif /* LIBC_SCCS and not lint */ #endif /* LIBC_SCCS and not lint */
......
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
#else #else
#include "config.h" #include "config.h"
#endif #endif
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint) #if defined(LIBC_SCCS) && !defined(lint)
#endif /* LIBC_SCCS and not lint */ #endif /* LIBC_SCCS and not lint */
......
This diff is collapsed.
This diff is collapsed.
/* $NetBSD: vis.h,v 1.16 2005/09/13 01:44:32 christos Exp $ */ /* $NetBSD: vis.h,v 1.19 2011/03/12 19:52:45 christos Exp $ */
/*- /*-
* Copyright (c) 1990, 1993 * Copyright (c) 1990, 1993
...@@ -39,24 +39,29 @@ ...@@ -39,24 +39,29 @@
/* /*
* to select alternate encoding format * to select alternate encoding format
*/ */
#define VIS_OCTAL 0x01 /* use octal \ddd format */ #define VIS_OCTAL 0x001 /* use octal \ddd format */
#define VIS_CSTYLE 0x02 /* use \[nrft0..] where appropiate */ #define VIS_CSTYLE 0x002 /* use \[nrft0..] where appropiate */
/* /*
* to alter set of characters encoded (default is to encode all * to alter set of characters encoded (default is to encode all
* non-graphic except space, tab, and newline). * non-graphic except space, tab, and newline).
*/ */
#define VIS_SP 0x04 /* also encode space */ #define VIS_SP 0x004 /* also encode space */
#define VIS_TAB 0x08 /* also encode tab */ #define VIS_TAB 0x008 /* also encode tab */
#define VIS_NL 0x10 /* also encode newline */ #define VIS_NL 0x010 /* also encode newline */
#define VIS_WHITE (VIS_SP | VIS_TAB | VIS_NL) #define VIS_WHITE (VIS_SP | VIS_TAB | VIS_NL)
#define VIS_SAFE 0x20 /* only encode "unsafe" characters */ #define VIS_SAFE 0x020 /* only encode "unsafe" characters */
/* /*
* other * other
*/ */
#define VIS_NOSLASH 0x40 /* inhibit printing '\' */ #define VIS_NOSLASH 0x040 /* inhibit printing '\' */
#define VIS_HTTPSTYLE 0x80 /* http-style escape % HEX HEX */ #define VIS_HTTP1808 0x080 /* http-style escape % hex hex */
#define VIS_HTTPSTYLE 0x080 /* http-style escape % hex hex */
#define VIS_MIMESTYLE 0x100 /* mime-style escape = HEX HEX */
#define VIS_HTTP1866 0x200 /* http-style &#num; or &string; */
#define VIS_NOESCAPE 0x400 /* don't decode `\' */
#define _VIS_END 0x800 /* for unvis */
/* /*
* unvis return codes * unvis return codes
...@@ -70,18 +75,41 @@ ...@@ -70,18 +75,41 @@
/* /*
* unvis flags * unvis flags
*/ */
#define UNVIS_END 1 /* no more characters */ #define UNVIS_END _VIS_END /* no more characters */
#include <sys/cdefs.h>
/* XXXMYSQL */
#ifndef __RENAME
#define __RENAME(x)
#endif
__BEGIN_DECLS __BEGIN_DECLS
char *vis(char *, int, int, int); char *vis(char *, int, int, int);
char *nvis(char *, size_t, int, int, int);
char *svis(char *, int, int, int, const char *); char *svis(char *, int, int, int, const char *);
char *snvis(char *, size_t, int, int, int, const char *);
int strvis(char *, const char *, int); int strvis(char *, const char *, int);
int strnvis(char *, size_t, const char *, int);
int strsvis(char *, const char *, int, const char *); int strsvis(char *, const char *, int, const char *);
int strsnvis(char *, size_t, const char *, int, const char *);
int strvisx(char *, const char *, size_t, int); int strvisx(char *, const char *, size_t, int);
int strnvisx(char *, size_t, const char *, size_t, int);
int strsvisx(char *, const char *, size_t, int, const char *); int strsvisx(char *, const char *, size_t, int, const char *);
int strsnvisx(char *, size_t, const char *, size_t, int, const char *);
int strunvis(char *, const char *); int strunvis(char *, const char *);
int strnunvis(char *, size_t, const char *);
int strunvisx(char *, const char *, int); int strunvisx(char *, const char *, int);
int unvis(char *, int, int *, int); int strnunvisx(char *, size_t, const char *, int);
#ifndef __LIBC12_SOURCE__
int unvis(char *, int, int *, int) __RENAME(__unvis50);
#endif
__END_DECLS __END_DECLS
#endif /* !_VIS_H_ */ #endif /* !_VIS_H_ */
/* $NetBSD: wcsdup.c,v 1.3 2008/05/26 13:17:48 haad Exp $ */
/*
* Copyright (C) 2006 Aleksey Cheusov
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee. Permission to modify the code and to distribute modified
* code is also granted without any restrictions.
*/
#ifndef HAVE_WCSDUP
#include "config.h"
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: wcsdup.c,v 1.3 2008/05/26 13:17:48 haad Exp $");
#endif /* LIBC_SCCS and not lint */
#include <stdlib.h>
#include <assert.h>
#include <wchar.h>
wchar_t *
wcsdup(const wchar_t *str)
{
wchar_t *copy;
size_t len;
_DIAGASSERT(str != NULL);
len = wcslen(str) + 1;
copy = malloc(len * sizeof (wchar_t));
if (!copy)
return NULL;
return wmemcpy(copy, str, len);
}
#endif
This diff is collapsed.
/* $NetBSD: parse.h,v 1.6 2005/05/29 04:58:15 lukem Exp $ */ /* $NetBSD: parse.h,v 1.7 2009/12/30 22:37:40 christos Exp $ */
/*- /*-
* Copyright (c) 1992, 1993 * Copyright (c) 1992, 1993
...@@ -40,9 +40,9 @@ ...@@ -40,9 +40,9 @@
#ifndef _h_el_parse #ifndef _h_el_parse
#define _h_el_parse #define _h_el_parse
protected int parse_line(EditLine *, const char *); protected int parse_line(EditLine *, const Char *);
protected int parse__escape(const char **); protected int parse__escape(const Char **);
protected char *parse__string(char *, const char *); protected Char *parse__string(Char *, const Char *);
protected int parse_cmd(EditLine *, const char *); protected int parse_cmd(EditLine *, const Char *);
#endif /* _h_el_parse */ #endif /* _h_el_parse */
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/* $NetBSD: read.h,v 1.6 2008/04/29 06:53:01 martin Exp $ */ /* $NetBSD: read.h,v 1.7 2009/12/30 22:37:40 christos Exp $ */
/*- /*-
* Copyright (c) 2001 The NetBSD Foundation, Inc. * Copyright (c) 2001 The NetBSD Foundation, Inc.
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
#ifndef _h_el_read #ifndef _h_el_read
#define _h_el_read #define _h_el_read
typedef int (*el_rfunc_t)(EditLine *, char *); typedef int (*el_rfunc_t)(EditLine *, Char *);
typedef struct el_read_t { typedef struct el_read_t {
el_rfunc_t read_char; /* Function to read a character */ el_rfunc_t read_char; /* Function to read a character */
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment