Commit a24a6a01 authored by Luis Soares's avatar Luis Soares

merge: 5.1-bt --> 5.1-bt local

parents fa8970fb 4ad5db32
...@@ -2270,8 +2270,10 @@ extern "C" char **new_mysql_completion (const char *text, int start, int end); ...@@ -2270,8 +2270,10 @@ extern "C" char **new_mysql_completion (const char *text, int start, int end);
if not. if not.
*/ */
#if defined(USE_NEW_READLINE_INTERFACE) || defined(USE_LIBEDIT_INTERFACE) #if defined(USE_NEW_READLINE_INTERFACE)
extern "C" char *no_completion(const char*,int) extern "C" char *no_completion(const char*,int)
#elif defined(USE_LIBEDIT_INTERFACE)
extern "C" int no_completion(const char*,int)
#else #else
extern "C" char *no_completion() extern "C" char *no_completion()
#endif #endif
......
## Process this file with automake to create Makefile.in ## Process this file with automake to create Makefile.in
# Makefile for the GNU readline library.
# Copyright (C) 1994,1996,1997 Free Software Foundation, Inc.
ASRC = $(srcdir)/vi.c $(srcdir)/emacs.c $(srcdir)/common.c ASRC = $(srcdir)/vi.c $(srcdir)/emacs.c $(srcdir)/common.c
AHDR = vi.h emacs.h common.h AHDR = vi.h emacs.h common.h
...@@ -12,32 +10,22 @@ noinst_LIBRARIES = libedit.a ...@@ -12,32 +10,22 @@ 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 history.c map.c prompt.c readline.c \
search.c tokenizer.c vi.c common.c emacs.c \ search.c tokenizer.c vi.c common.c emacs.c \
hist.c key.c parse.c read.c refresh.c sig.c term.c \ hist.c key.c parse.c read.c refresh.c sig.c term.c \
tty.c help.c fcns.c tty.c help.c fcns.c filecomplete.c \
np/unvis.c np/strlcpy.c np/vis.c np/strlcat.c \
EXTRA_libedit_a_SOURCES = np/unvis.c np/strlcpy.c np/vis.c np/strlcat.c \ np/fgetln.c
np/fgetln.c
libedit_a_LIBADD = @LIBEDIT_LOBJECTS@ libedit_a_LIBADD = @LIBEDIT_LOBJECTS@
libedit_a_DEPENDENCIES = @LIBEDIT_LOBJECTS@ libedit_a_DEPENDENCIES = @LIBEDIT_LOBJECTS@
noinst_HEADERS = readline/readline.h \ pkginclude_HEADERS = readline/readline.h
\
chared.h el.h el_term.h histedit.h key.h parse.h refresh.h sig.h \
sys.h tokenizer.h config.h hist.h map.h prompt.h read.h \
search.h tty.h libedit_term.h vis.h
EXTRA_DIST = makelist.sh np/unvis.c np/strlcpy.c np/vis.c np/vis.h np/strlcat.c np/fgetln.c noinst_HEADERS = chared.h el.h el_term.h histedit.h key.h parse.h refresh.h sig.h \
sys.h config.h hist.h map.h prompt.h read.h \
search.h tty.h filecomplete.h np/vis.h
CLEANFILES = makelist common.h emacs.h vi.h fcns.h help.h fcns.c help.c EXTRA_DIST = makelist.sh
# Make sure to include stuff from this directory first, to get right "config.h" CLEANFILES = makelist common.h emacs.h vi.h fcns.h help.h fcns.c help.c
# Automake puts into DEFAULT_INCLUDES this source and corresponding
# build directory together with ../../include to let all make files
# find the central "config.h". This variable is used before INCLUDES
# above. But in automake 1.10 the order of these are changed. Put the
# includes of this directory into DEFS to always be sure it is first
# before DEFAULT_INCLUDES on the compile line.
DEFS = -DUNDEF_THREADS_HACK -DHAVE_CONFIG_H -DNO_KILL_INTR -I. -I$(srcdir)
SUFFIXES = .sh SUFFIXES = .sh
...@@ -101,6 +89,4 @@ term.o: vi.h emacs.h common.h help.h fcns.h ...@@ -101,6 +89,4 @@ term.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
filecomplete.o: vi.h emacs.h common.h help.h fcns.h
# Don't update the files from bitkeeper
%::SCCS/s.%
An approximate method to merge from upstream is:
# Fetch latest from upstream (we also include some compat stuff)
$ CVS_RSH=ssh; export CVS_RSH
$ CVSROOT="anoncvs@stripped:/cvsroot"
$ cvs co -d libedit -P src/lib/libedit
$ mkdir libedit/np
$ for f in src/common/lib/libc/string/strlcat.c \
> src/common/lib/libc/string/strlcpy.c \
> src/include/vis.h \
> src/lib/libc/gen/unvis.c \
> src/lib/libc/gen/vis.c \
> src/tools/compat/fgetln.c
> do
> cvs co -P ${f}
> mv ${f} libedit/np
> done
$ rm -rf src
$ cd libedit
# Remove files we don't need/use
$ rm -rf CVS TEST Makefile shlib_version *.[0-9]
$ (cd readline; rm -rf CVS Makefile)
# Rename files to match our naming
$ mv makelist makelist.sh
$ mv term.h el_term.h
# Remove NetBSD-specific bits
$ for file in $(find . -type f)
> do
> cp ${file} ${file}.orig
> sed -e 's/#include "term.h"/#include "el_term.h"/g' \
> -e 's/sig_handler/el_sig_handler/g' \
> -e 's/isprint/el_isprint/g' \
> -e '/^__RCSID/d' \
> ${file}.orig >${file}
> rm ${file}.orig
> done
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
a 'clean' diff against upstream you can use the above commands but use
cvs co -D "2009/02/06 20:09:00" [..]
to fetch the baseline of most recent merge.
Please feed any fixes to Jonathan Perkin <jperkin@stripped> who will endeavour
to merge them upstream and keep diffs minimal.
/* $NetBSD: test.c,v 1.9 2000/09/04 23:36:41 lukem Exp $ */
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Christos Zoulas of Cornell University.
*
* 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 University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University 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 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 <sys/cdefs.h>
#include "compat.h"
#ifndef lint
__COPYRIGHT("@(#) Copyright (c) 1992, 1993\n\
The Regents of the University of California. All rights reserved.\n");
#endif /* not lint */
#if !defined(lint) && !defined(SCCSID)
#if 0
static char sccsid[] = "@(#)test.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: test.c,v 1.9 2000/09/04 23:36:41 lukem Exp $");
#endif
#endif /* not lint && not SCCSID */
/*
* test.c: A little test program
*/
#include "sys.h"
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <sys/wait.h>
#include <ctype.h>
#include <stdlib.h>
#include <unistd.h>
#include <dirent.h>
#include "histedit.h"
#include "tokenizer.h"
static int continuation = 0;
static EditLine *el = NULL;
static u_char complete(EditLine *, int);
int main(int, char **);
static char *prompt(EditLine *);
static void sig(int);
static char *
prompt(EditLine *el)
{
static char a[] = "Edit$";
static char b[] = "Edit>";
return (continuation ? b : a);
}
static void
sig(int i)
{
(void) fprintf(stderr, "Got signal %d.\n", i);
el_reset(el);
}
static unsigned char
complete(EditLine *el, int ch)
{
DIR *dd = opendir(".");
struct dirent *dp;
const char* ptr;
const LineInfo *lf = el_line(el);
int len;
/*
* Find the last word
*/
for (ptr = lf->cursor - 1; !isspace(*ptr) && ptr > lf->buffer; ptr--)
continue;
len = lf->cursor - ++ptr;
for (dp = readdir(dd); dp != NULL; dp = readdir(dd)) {
if (len > strlen(dp->d_name))
continue;
if (strncmp(dp->d_name, ptr, len) == 0) {
closedir(dd);
if (el_insertstr(el, &dp->d_name[len]) == -1)
return (CC_ERROR);
else
return (CC_REFRESH);
}
}
closedir(dd);
return (CC_ERROR);
}
int
main(int argc, char *argv[])
{
int num;
const char *buf;
Tokenizer *tok;
int lastevent = 0, ncontinuation;
History *hist;
HistEvent ev;
(void) signal(SIGINT, sig);
(void) signal(SIGQUIT, sig);
(void) signal(SIGHUP, sig);
(void) signal(SIGTERM, sig);
hist = history_init(); /* Init the builtin history */
/* Remember 100 events */
history(hist, &ev, H_SETSIZE, 100);
tok = tok_init(NULL); /* Initialize the tokenizer */
/* Initialize editline */
el = el_init(*argv, stdin, stdout, stderr);
el_set(el, EL_EDITOR, "vi"); /* Default editor is vi */
el_set(el, EL_SIGNAL, 1); /* Handle signals gracefully */
el_set(el, EL_PROMPT, prompt); /* Set the prompt function */
/* Tell editline to use this history interface */
el_set(el, EL_HIST, history, hist);
/* Add a user-defined function */
el_set(el, EL_ADDFN, "ed-complete", "Complete argument", complete);
/* Bind tab to it */
el_set(el, EL_BIND, "^I", "ed-complete", NULL);
/*
* Bind j, k in vi command mode to previous and next line, instead
* of previous and next history.
*/
el_set(el, EL_BIND, "-a", "k", "ed-prev-line", NULL);
el_set(el, EL_BIND, "-a", "j", "ed-next-line", NULL);
/*
* Source the user's defaults file.
*/
el_source(el, NULL);
while ((buf = el_gets(el, &num)) != NULL && num != 0) {
int ac;
char **av;
#ifdef DEBUG
(void) fprintf(stderr, "got %d %s", num, buf);
#endif
if (!continuation && num == 1)
continue;
if (tok_line(tok, buf, &ac, &av) > 0)
ncontinuation = 1;
#if 0
if (continuation) {
/*
* Append to the right event in case the user
* moved around in history.
*/
if (history(hist, &ev, H_SET, lastevent) == -1)
err(1, "%d: %s\n", lastevent, ev.str);
history(hist, &ev, H_ADD , buf);
} else {
history(hist, &ev, H_ENTER, buf);
lastevent = ev.num;
}
#else
/* Simpler */
history(hist, &ev, continuation ? H_APPEND : H_ENTER, buf);
#endif
continuation = ncontinuation;
ncontinuation = 0;
if (strcmp(av[0], "history") == 0) {
int rv;
switch (ac) {
case 1:
for (rv = history(hist, &ev, H_LAST); rv != -1;
rv = history(hist, &ev, H_PREV))
(void) fprintf(stdout, "%4d %s",
ev.num, ev.str);
break;
case 2:
if (strcmp(av[1], "clear") == 0)
history(hist, &ev, H_CLEAR);
else
goto badhist;
break;
case 3:
if (strcmp(av[1], "load") == 0)
history(hist, &ev, H_LOAD, av[2]);
else if (strcmp(av[1], "save") == 0)
history(hist, &ev, H_SAVE, av[2]);
break;
badhist:
default:
(void) fprintf(stderr,
"Bad history arguments\n");
break;
}
} else if (el_parse(el, ac, av) == -1) {
switch (fork()) {
case 0:
execvp(av[0], av);
perror(av[0]);
_exit(1);
/*NOTREACHED*/
break;
case -1:
perror("fork");
break;
default:
if (wait(&num) == -1)
perror("wait");
(void) fprintf(stderr, "Exit %x\n", num);
break;
}
}
tok_reset(tok);
}
el_end(el);
tok_end(tok);
history_end(hist);
return (0);
}
/* $NetBSD: chared.c,v 1.22 2004/08/13 12:10:38 mycroft Exp $ */ /* $NetBSD: chared.c,v 1.26 2009/02/06 12:45:25 sketch Exp $ */
/*- /*-
* Copyright (c) 1992, 1993 * Copyright (c) 1992, 1993
...@@ -32,7 +32,13 @@ ...@@ -32,7 +32,13 @@
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
#include <config.h> #include "config.h"
#if !defined(lint) && !defined(SCCSID)
#if 0
static char sccsid[] = "@(#)chared.c 8.1 (Berkeley) 6/4/93";
#else
#endif
#endif /* not lint && not SCCSID */
/* /*
* chared.c: Character editor utilities * chared.c: Character editor utilities
...@@ -40,6 +46,8 @@ ...@@ -40,6 +46,8 @@
#include <stdlib.h> #include <stdlib.h>
#include "el.h" #include "el.h"
private void ch__clearmacro (EditLine *);
/* value to leave unused in line buffer */ /* value to leave unused in line buffer */
#define EL_LEAVE 2 #define EL_LEAVE 2
...@@ -51,13 +59,13 @@ cv_undo(EditLine *el) ...@@ -51,13 +59,13 @@ cv_undo(EditLine *el)
{ {
c_undo_t *vu = &el->el_chared.c_undo; c_undo_t *vu = &el->el_chared.c_undo;
c_redo_t *r = &el->el_chared.c_redo; c_redo_t *r = &el->el_chared.c_redo;
int size; unsigned int size;
/* Save entire line for undo */ /* Save entire line for undo */
size = el->el_line.lastchar - el->el_line.buffer; size = el->el_line.lastchar - el->el_line.buffer;
vu->len = size; vu->len = size;
vu->cursor = el->el_line.cursor - el->el_line.buffer; vu->cursor = el->el_line.cursor - el->el_line.buffer;
memcpy(vu->buf, el->el_line.buffer, (size_t)size); memcpy(vu->buf, el->el_line.buffer, size);
/* save command info for redo */ /* save command info for redo */
r->count = el->el_state.doingarg ? el->el_state.argument : 0; r->count = el->el_state.doingarg ? el->el_state.argument : 0;
...@@ -439,6 +447,8 @@ cv__endword(char *p, char *high, int n, int (*wtest)(int)) ...@@ -439,6 +447,8 @@ cv__endword(char *p, char *high, int n, int (*wtest)(int))
protected int protected int
ch_init(EditLine *el) ch_init(EditLine *el)
{ {
c_macro_t *ma = &el->el_chared.c_macro;
el->el_line.buffer = (char *) el_malloc(EL_BUFSIZ); el->el_line.buffer = (char *) el_malloc(EL_BUFSIZ);
if (el->el_line.buffer == NULL) if (el->el_line.buffer == NULL)
return (-1); return (-1);
...@@ -479,11 +489,10 @@ ch_init(EditLine *el) ...@@ -479,11 +489,10 @@ ch_init(EditLine *el)
el->el_state.argument = 1; el->el_state.argument = 1;
el->el_state.lastcmd = ED_UNASSIGNED; el->el_state.lastcmd = ED_UNASSIGNED;
el->el_chared.c_macro.level = -1; ma->level = -1;
el->el_chared.c_macro.offset = 0; ma->offset = 0;
el->el_chared.c_macro.macro = (char **) el_malloc(EL_MAXMACRO * ma->macro = (char **) el_malloc(EL_MAXMACRO * sizeof(char *));
sizeof(char *)); if (ma->macro == NULL)
if (el->el_chared.c_macro.macro == NULL)
return (-1); return (-1);
return (0); return (0);
} }
...@@ -492,7 +501,7 @@ ch_init(EditLine *el) ...@@ -492,7 +501,7 @@ ch_init(EditLine *el)
* Reset the character editor * Reset the character editor
*/ */
protected void protected void
ch_reset(EditLine *el) ch_reset(EditLine *el, int mclear)
{ {
el->el_line.cursor = el->el_line.buffer; el->el_line.cursor = el->el_line.buffer;
el->el_line.lastchar = el->el_line.buffer; el->el_line.lastchar = el->el_line.buffer;
...@@ -513,9 +522,19 @@ ch_reset(EditLine *el) ...@@ -513,9 +522,19 @@ ch_reset(EditLine *el)
el->el_state.argument = 1; el->el_state.argument = 1;
el->el_state.lastcmd = ED_UNASSIGNED; el->el_state.lastcmd = ED_UNASSIGNED;
el->el_chared.c_macro.level = -1;
el->el_history.eventno = 0; el->el_history.eventno = 0;
if (mclear)
ch__clearmacro(el);
}
private void
ch__clearmacro(el)
EditLine *el;
{
c_macro_t *ma = &el->el_chared.c_macro;
while (ma->level >= 0)
el_free((ptr_t)ma->macro[ma->level--]);
} }
/* ch_enlargebufs(): /* ch_enlargebufs():
...@@ -623,9 +642,9 @@ ch_end(EditLine *el) ...@@ -623,9 +642,9 @@ ch_end(EditLine *el)
el->el_chared.c_redo.cmd = ED_UNASSIGNED; el->el_chared.c_redo.cmd = ED_UNASSIGNED;
el_free((ptr_t) el->el_chared.c_kill.buf); el_free((ptr_t) el->el_chared.c_kill.buf);
el->el_chared.c_kill.buf = NULL; el->el_chared.c_kill.buf = NULL;
ch_reset(el, 1);
el_free((ptr_t) el->el_chared.c_macro.macro); el_free((ptr_t) el->el_chared.c_macro.macro);
el->el_chared.c_macro.macro = NULL; el->el_chared.c_macro.macro = NULL;
ch_reset(el);
} }
......
/* $NetBSD: chared.h,v 1.14 2004/08/13 12:10:39 mycroft Exp $ */ /* $NetBSD: chared.h,v 1.17 2006/03/06 21:11:56 christos Exp $ */
/*- /*-
* Copyright (c) 1992, 1993 * Copyright (c) 1992, 1993
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
#define EL_MAXMACRO 10 #define EL_MAXMACRO 10
/* /*
* This is a issue of basic "vi" look-and-feel. Defining VI_MOVE works * This is an issue of basic "vi" look-and-feel. Defining VI_MOVE works
* like real vi: i.e. the transition from command<->insert modes moves * like real vi: i.e. the transition from command<->insert modes moves
* the cursor. * the cursor.
* *
...@@ -116,11 +116,10 @@ typedef struct el_chared_t { ...@@ -116,11 +116,10 @@ typedef struct el_chared_t {
} el_chared_t; } el_chared_t;
#define STReof "^D\b\b"
#define STRQQ "\"\"" #define STRQQ "\"\""
#define isglob(a) (strchr("*[]?", (a)) != NULL) #define isglob(a) (strchr("*[]?", (a)) != NULL)
#define isword(a) (isprint(a)) #define isword(a) (el_isprint(a))
#define NOP 0x00 #define NOP 0x00
#define DELETE 0x01 #define DELETE 0x01
...@@ -161,7 +160,7 @@ protected int c_gets(EditLine *, char *, const char *); ...@@ -161,7 +160,7 @@ 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 *); protected void ch_reset(EditLine *, int);
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: common.c,v 1.16 2003/08/07 16:44:30 agc Exp $ */ /* $NetBSD: common.c,v 1.21 2008/09/30 08:37:42 aymeric Exp $ */
/*- /*-
* Copyright (c) 1992, 1993 * Copyright (c) 1992, 1993
...@@ -32,7 +32,13 @@ ...@@ -32,7 +32,13 @@
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
#include <config.h> #include "config.h"
#if !defined(lint) && !defined(SCCSID)
#if 0
static char sccsid[] = "@(#)common.c 8.1 (Berkeley) 6/4/93";
#else
#endif
#endif /* not lint && not SCCSID */
/* /*
* common.c: Common Editor functions * common.c: Common Editor functions
...@@ -130,7 +136,7 @@ ed_delete_prev_word(EditLine *el, int c __attribute__((__unused__))) ...@@ -130,7 +136,7 @@ ed_delete_prev_word(EditLine *el, int c __attribute__((__unused__)))
*/ */
protected el_action_t protected el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
ed_delete_next_char(EditLine *el, int c __attribute__((__unused__))) ed_delete_next_char(EditLine *el, int c)
{ {
#ifdef notdef /* XXX */ #ifdef notdef /* XXX */
#define EL el->el_line #define EL el->el_line
...@@ -147,9 +153,8 @@ ed_delete_next_char(EditLine *el, int c __attribute__((__unused__))) ...@@ -147,9 +153,8 @@ ed_delete_next_char(EditLine *el, int c __attribute__((__unused__)))
#ifdef KSHVI #ifdef KSHVI
return (CC_ERROR); return (CC_ERROR);
#else #else
term_overwrite(el, STReof, 4); /* then do an EOF */
/* then do a EOF */ term_writechar(el, c);
term__flush();
return (CC_EOF); return (CC_EOF);
#endif #endif
} else { } else {
...@@ -207,13 +212,13 @@ ed_move_to_end(EditLine *el, int c __attribute__((__unused__))) ...@@ -207,13 +212,13 @@ ed_move_to_end(EditLine *el, int c __attribute__((__unused__)))
el->el_line.cursor = el->el_line.lastchar; el->el_line.cursor = el->el_line.lastchar;
if (el->el_map.type == MAP_VI) { if (el->el_map.type == MAP_VI) {
#ifdef VI_MOVE
el->el_line.cursor--;
#endif
if (el->el_chared.c_vcmd.action != NOP) { if (el->el_chared.c_vcmd.action != NOP) {
cv_delfini(el); cv_delfini(el);
return (CC_REFRESH); return (CC_REFRESH);
} }
#ifdef VI_MOVE
el->el_line.cursor--;
#endif
} }
return (CC_CURSOR); return (CC_CURSOR);
} }
...@@ -609,7 +614,7 @@ protected el_action_t ...@@ -609,7 +614,7 @@ protected el_action_t
ed_start_over(EditLine *el, int c __attribute__((__unused__))) ed_start_over(EditLine *el, int c __attribute__((__unused__)))
{ {
ch_reset(el); ch_reset(el, 0);
return (CC_REFRESH); return (CC_REFRESH);
} }
...@@ -904,7 +909,7 @@ ed_command(EditLine *el, int c __attribute__((__unused__))) ...@@ -904,7 +909,7 @@ ed_command(EditLine *el, int c __attribute__((__unused__)))
int tmplen; int tmplen;
tmplen = c_gets(el, tmpbuf, "\n: "); tmplen = c_gets(el, tmpbuf, "\n: ");
term__putc('\n'); term__putc(el, '\n');
if (tmplen < 0 || (tmpbuf[tmplen] = 0, parse_line(el, tmpbuf)) == -1) if (tmplen < 0 || (tmpbuf[tmplen] = 0, parse_line(el, tmpbuf)) == -1)
term_beep(el); term_beep(el);
......
#ifndef __LIBEDIT_COMPATH_H
#define __LIBEDIT_COMPATH_H
#define __RCSID(x)
#define __COPYRIGHT(x)
#include "compat_conf.h"
#ifndef HAVE_VIS_H
/* string visual representation - may want to reimplement */
#define strvis(d,s,m) strcpy(d,s)
#define strunvis(d,s) strcpy(d,s)
#endif
#ifndef HAVE_FGETLN
#include "fgetln.h"
#endif
#ifndef HAVE_ISSETUGID
#define issetugid() (getuid()!=geteuid() || getegid()!=getgid())
#endif
#ifndef HAVE_STRLCPY
#include "strlcpy.h"
#endif
#if HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
#endif
#ifndef __P
#ifdef __STDC__
#define __P(x) x
#else
#define __P(x) ()
#endif
#endif
#if !defined(__attribute__) && (defined(__cplusplus) || !defined(__GNUC__) || __GNUC__ == 2 && __GNUC_MINOR__ < 8)
#define __attribute__(A)
#endif
#endif
#include "my_config.h" #include "my_config.h"
#include "sys.h" #include "sys.h"
#if defined(LIBC_SCCS) && !defined(lint)
#define __RCSID(x)
#define __COPYRIGHT(x)
#endif
#define __RENAME(x)
#define _DIAGASSERT(x)
#if !defined(__attribute__) && (defined(__cplusplus) || !defined(__GNUC__) || __GNUC__ == 2 && __GNUC_MINOR__ < 8)
#define __attribute__(A)
#endif
This diff is collapsed.
This diff is collapsed.
/* $NetBSD: el.c,v 1.39 2004/07/08 00:51:36 christos Exp $ */ /* $NetBSD: el.c,v 1.47 2009/01/18 12:17:24 lukem Exp $ */
/*- /*-
* Copyright (c) 1992, 1993 * Copyright (c) 1992, 1993
...@@ -32,7 +32,13 @@ ...@@ -32,7 +32,13 @@
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
#include <config.h> #include "config.h"
#if !defined(lint) && !defined(SCCSID)
#if 0
static char sccsid[] = "@(#)el.c 8.2 (Berkeley) 1/3/94";
#else
#endif
#endif /* not lint && not SCCSID */
/* /*
* el.c: EditLine interface functions * el.c: EditLine interface functions
...@@ -58,9 +64,12 @@ el_init(const char *prog, FILE *fin, FILE *fout, FILE *ferr) ...@@ -58,9 +64,12 @@ el_init(const char *prog, FILE *fin, FILE *fout, FILE *ferr)
memset(el, 0, sizeof(EditLine)); memset(el, 0, sizeof(EditLine));
el->el_infd = fileno(fin); el->el_infile = fin;
el->el_outfile = fout; el->el_outfile = fout;
el->el_errfile = ferr; el->el_errfile = ferr;
el->el_infd = fileno(fin);
if ((el->el_prog = el_strdup(prog)) == NULL) { if ((el->el_prog = el_strdup(prog)) == NULL) {
el_free(el); el_free(el);
return NULL; return NULL;
...@@ -126,7 +135,7 @@ el_reset(EditLine *el) ...@@ -126,7 +135,7 @@ el_reset(EditLine *el)
{ {
tty_cookedmode(el); tty_cookedmode(el);
ch_reset(el); /* XXX: Do we want that? */ ch_reset(el, 0); /* XXX: Do we want that? */
} }
...@@ -136,29 +145,29 @@ el_reset(EditLine *el) ...@@ -136,29 +145,29 @@ el_reset(EditLine *el)
public int public int
el_set(EditLine *el, int op, ...) el_set(EditLine *el, int op, ...)
{ {
va_list va; va_list ap;
int rv = 0; int rv = 0;
if (el == NULL) if (el == NULL)
return (-1); return (-1);
va_start(va, op); va_start(ap, op);
switch (op) { switch (op) {
case EL_PROMPT: case EL_PROMPT:
case EL_RPROMPT: case EL_RPROMPT:
rv = prompt_set(el, va_arg(va, el_pfunc_t), op); rv = prompt_set(el, va_arg(ap, el_pfunc_t), op);
break; break;
case EL_TERMINAL: case EL_TERMINAL:
rv = term_set(el, va_arg(va, char *)); rv = term_set(el, va_arg(ap, char *));
break; break;
case EL_EDITOR: case EL_EDITOR:
rv = map_set_editor(el, va_arg(va, char *)); rv = map_set_editor(el, va_arg(ap, char *));
break; break;
case EL_SIGNAL: case EL_SIGNAL:
if (va_arg(va, int)) if (va_arg(ap, int))
el->el_flags |= HANDLE_SIGNALS; el->el_flags |= HANDLE_SIGNALS;
else else
el->el_flags &= ~HANDLE_SIGNALS; el->el_flags &= ~HANDLE_SIGNALS;
...@@ -167,6 +176,7 @@ el_set(EditLine *el, int op, ...) ...@@ -167,6 +176,7 @@ el_set(EditLine *el, int op, ...)
case EL_BIND: case EL_BIND:
case EL_TELLTC: case EL_TELLTC:
case EL_SETTC: case EL_SETTC:
case EL_GETTC:
case EL_ECHOTC: case EL_ECHOTC:
case EL_SETTY: case EL_SETTY:
{ {
...@@ -174,7 +184,7 @@ el_set(EditLine *el, int op, ...) ...@@ -174,7 +184,7 @@ el_set(EditLine *el, int op, ...)
int i; int i;
for (i = 1; i < 20; i++) for (i = 1; i < 20; i++)
if ((argv[i] = va_arg(va, char *)) == NULL) if ((argv[i] = va_arg(ap, char *)) == NULL)
break; break;
switch (op) { switch (op) {
...@@ -213,9 +223,9 @@ el_set(EditLine *el, int op, ...) ...@@ -213,9 +223,9 @@ el_set(EditLine *el, int op, ...)
case EL_ADDFN: case EL_ADDFN:
{ {
char *name = va_arg(va, char *); char *name = va_arg(ap, char *);
char *help = va_arg(va, char *); char *help = va_arg(ap, char *);
el_func_t func = va_arg(va, el_func_t); el_func_t func = va_arg(ap, el_func_t);
rv = map_addfunc(el, name, help, func); rv = map_addfunc(el, name, help, func);
break; break;
...@@ -223,15 +233,15 @@ el_set(EditLine *el, int op, ...) ...@@ -223,15 +233,15 @@ el_set(EditLine *el, int op, ...)
case EL_HIST: case EL_HIST:
{ {
hist_fun_t func = va_arg(va, hist_fun_t); hist_fun_t func = va_arg(ap, hist_fun_t);
ptr_t ptr = va_arg(va, char *); ptr_t ptr = va_arg(ap, char *);
rv = hist_set(el, func, ptr); rv = hist_set(el, func, ptr);
break; break;
} }
case EL_EDITMODE: case EL_EDITMODE:
if (va_arg(va, int)) if (va_arg(ap, int))
el->el_flags &= ~EDIT_DISABLED; el->el_flags &= ~EDIT_DISABLED;
else else
el->el_flags |= EDIT_DISABLED; el->el_flags |= EDIT_DISABLED;
...@@ -240,17 +250,17 @@ el_set(EditLine *el, int op, ...) ...@@ -240,17 +250,17 @@ el_set(EditLine *el, int op, ...)
case EL_GETCFN: case EL_GETCFN:
{ {
el_rfunc_t rc = va_arg(va, el_rfunc_t); el_rfunc_t rc = va_arg(ap, el_rfunc_t);
rv = el_read_setfn(el, rc); rv = el_read_setfn(el, rc);
break; break;
} }
case EL_CLIENTDATA: case EL_CLIENTDATA:
el->el_data = va_arg(va, void *); el->el_data = va_arg(ap, void *);
break; break;
case EL_UNBUFFERED: case EL_UNBUFFERED:
rv = va_arg(va, int); rv = va_arg(ap, int);
if (rv && !(el->el_flags & UNBUFFERED)) { if (rv && !(el->el_flags & UNBUFFERED)) {
el->el_flags |= UNBUFFERED; el->el_flags |= UNBUFFERED;
read_prepare(el); read_prepare(el);
...@@ -262,7 +272,7 @@ el_set(EditLine *el, int op, ...) ...@@ -262,7 +272,7 @@ el_set(EditLine *el, int op, ...)
break; break;
case EL_PREP_TERM: case EL_PREP_TERM:
rv = va_arg(va, int); rv = va_arg(ap, int);
if (rv) if (rv)
(void) tty_rawmode(el); (void) tty_rawmode(el);
else else
...@@ -270,12 +280,45 @@ el_set(EditLine *el, int op, ...) ...@@ -270,12 +280,45 @@ el_set(EditLine *el, int op, ...)
rv = 0; rv = 0;
break; break;
case EL_SETFP:
{
FILE *fp;
int what;
what = va_arg(ap, int);
fp = va_arg(ap, FILE *);
rv = 0;
switch (what) {
case 0:
el->el_infile = fp;
el->el_infd = fileno(fp);
break;
case 1:
el->el_outfile = fp;
break;
case 2:
el->el_errfile = fp;
break;
default:
rv = -1;
break;
}
break;
}
case EL_REFRESH:
re_clear_display(el);
re_refresh(el);
term__flush(el);
break;
default: default:
rv = -1; rv = -1;
break; break;
} }
va_end(va); va_end(ap);
return (rv); return (rv);
} }
...@@ -284,90 +327,71 @@ el_set(EditLine *el, int op, ...) ...@@ -284,90 +327,71 @@ el_set(EditLine *el, int op, ...)
* retrieve the editline parameters * retrieve the editline parameters
*/ */
public int public int
el_get(EditLine *el, int op, void *ret) el_get(EditLine *el, int op, ...)
{ {
va_list ap;
int rv; int rv;
if (el == NULL || ret == NULL) if (el == NULL)
return (-1); return -1;
va_start(ap, op);
switch (op) { switch (op) {
case EL_PROMPT: case EL_PROMPT:
case EL_RPROMPT: case EL_RPROMPT:
rv = prompt_get(el, (void *) &ret, op); rv = prompt_get(el, va_arg(ap, el_pfunc_t *), op);
break; break;
case EL_EDITOR: case EL_EDITOR:
rv = map_get_editor(el, (void *) &ret); rv = map_get_editor(el, va_arg(ap, const char **));
break; break;
case EL_SIGNAL: case EL_SIGNAL:
*((int *) ret) = (el->el_flags & HANDLE_SIGNALS); *va_arg(ap, int *) = (el->el_flags & HANDLE_SIGNALS);
rv = 0; rv = 0;
break; break;
case EL_EDITMODE: case EL_EDITMODE:
*((int *) ret) = (!(el->el_flags & EDIT_DISABLED)); *va_arg(ap, int *) = !(el->el_flags & EDIT_DISABLED);
rv = 0; rv = 0;
break; break;
case EL_TERMINAL: case EL_TERMINAL:
term_get(el, (const char **)ret); term_get(el, va_arg(ap, const char **));
rv = 0; rv = 0;
break; break;
#if 0 /* XXX */ case EL_GETTC:
case EL_BIND:
case EL_TELLTC:
case EL_SETTC:
case EL_ECHOTC:
case EL_SETTY:
{ {
const char *argv[20]; static char name[] = "gettc";
char *argv[20];
int i; int i;
for (i = 1; i < sizeof(argv) / sizeof(argv[0]); i++) for (i = 1; i < (int)(sizeof(argv) / sizeof(argv[0])); i++)
if ((argv[i] = va_arg(va, char *)) == NULL) if ((argv[i] = va_arg(ap, char *)) == NULL)
break; break;
switch (op) { switch (op) {
case EL_BIND: case EL_GETTC:
argv[0] = "bind"; argv[0] = name;
rv = map_bind(el, i, argv); rv = term_gettc(el, i, argv);
break;
case EL_TELLTC:
argv[0] = "telltc";
rv = term_telltc(el, i, argv);
break;
case EL_SETTC:
argv[0] = "settc";
rv = term_settc(el, i, argv);
break;
case EL_ECHOTC:
argv[0] = "echotc";
rv = term_echotc(el, i, argv);
break;
case EL_SETTY:
argv[0] = "setty";
rv = tty_stty(el, i, argv);
break; break;
default: default:
rv = -1; rv = -1;
EL_ABORT((el->errfile, "Bad op %d\n", op)); EL_ABORT((el->el_errfile, "Bad op %d\n", op));
break; break;
} }
break; break;
} }
#if 0 /* XXX */
case EL_ADDFN: case EL_ADDFN:
{ {
char *name = va_arg(va, char *); char *name = va_arg(ap, char *);
char *help = va_arg(va, char *); char *help = va_arg(ap, char *);
el_func_t func = va_arg(va, el_func_t); el_func_t func = va_arg(ap, el_func_t);
rv = map_addfunc(el, name, help, func); rv = map_addfunc(el, name, help, func);
break; break;
...@@ -375,31 +399,57 @@ el_get(EditLine *el, int op, void *ret) ...@@ -375,31 +399,57 @@ el_get(EditLine *el, int op, void *ret)
case EL_HIST: case EL_HIST:
{ {
hist_fun_t func = va_arg(va, hist_fun_t); hist_fun_t func = va_arg(ap, hist_fun_t);
ptr_t ptr = va_arg(va, char *); ptr_t ptr = va_arg(ap, char *);
rv = hist_set(el, func, ptr); rv = hist_set(el, func, ptr);
} }
break; break;
#endif /* XXX */ #endif /* XXX */
case EL_GETCFN: case EL_GETCFN:
*((el_rfunc_t *)ret) = el_read_getfn(el); *va_arg(ap, el_rfunc_t *) = el_read_getfn(el);
rv = 0; rv = 0;
break; break;
case EL_CLIENTDATA: case EL_CLIENTDATA:
*((void **)ret) = el->el_data; *va_arg(ap, void **) = el->el_data;
rv = 0; rv = 0;
break; break;
case EL_UNBUFFERED: case EL_UNBUFFERED:
*((int *) ret) = (!(el->el_flags & UNBUFFERED)); *va_arg(ap, int *) = (!(el->el_flags & UNBUFFERED));
rv = 0; rv = 0;
break; break;
case EL_GETFP:
{
int what;
FILE **fpp;
what = va_arg(ap, int);
fpp = va_arg(ap, FILE **);
rv = 0;
switch (what) {
case 0:
*fpp = el->el_infile;
break;
case 1:
*fpp = el->el_outfile;
break;
case 2:
*fpp = el->el_errfile;
break;
default:
rv = -1;
break;
}
break;
}
default: default:
rv = -1; rv = -1;
break;
} }
va_end(ap);
return (rv); return (rv);
} }
...@@ -428,17 +478,17 @@ el_source(EditLine *el, const char *fname) ...@@ -428,17 +478,17 @@ el_source(EditLine *el, const char *fname)
fp = NULL; fp = NULL;
if (fname == NULL) { if (fname == NULL) {
#ifdef HAVE_ISSETUGID
static const char elpath[] = "/.editrc"; static const char elpath[] = "/.editrc";
/* XXXMYSQL: Portability fix (for which platforms?) */
#ifdef MAXPATHLEN #ifdef MAXPATHLEN
char path[MAXPATHLEN]; char path[MAXPATHLEN];
#else #else
char path[4096]; char path[4096];
#endif #endif
#ifdef HAVE_ISSETUGID
if (issetugid()) if (issetugid())
return (-1); return (-1);
#endif
if ((ptr = getenv("HOME")) == NULL) if ((ptr = getenv("HOME")) == NULL)
return (-1); return (-1);
if (strlcpy(path, ptr, sizeof(path)) >= sizeof(path)) if (strlcpy(path, ptr, sizeof(path)) >= sizeof(path))
...@@ -446,6 +496,14 @@ el_source(EditLine *el, const char *fname) ...@@ -446,6 +496,14 @@ el_source(EditLine *el, const char *fname)
if (strlcat(path, elpath, sizeof(path)) >= sizeof(path)) if (strlcat(path, elpath, sizeof(path)) >= sizeof(path))
return (-1); return (-1);
fname = path; fname = path;
#else
/*
* If issetugid() is missing, always return an error, in order
* to keep from inadvertently opening up the user to a security
* hole.
*/
return (-1);
#endif
} }
if (fp == NULL) if (fp == NULL)
fp = fopen(fname, "r"); fp = fopen(fname, "r");
......
/* $NetBSD: el.h,v 1.16 2003/10/18 23:48:42 christos Exp $ */ /* $NetBSD: el.h,v 1.17 2006/12/15 22:13:33 christos Exp $ */
/*- /*-
* Copyright (c) 1992, 1993 * Copyright (c) 1992, 1993
...@@ -110,6 +110,7 @@ typedef struct el_state_t { ...@@ -110,6 +110,7 @@ typedef struct el_state_t {
struct editline { struct editline {
char *el_prog; /* the program name */ char *el_prog; /* the program name */
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 */
...@@ -136,7 +137,8 @@ struct editline { ...@@ -136,7 +137,8 @@ struct editline {
protected int el_editmode(EditLine *, int, const char **); protected int el_editmode(EditLine *, int, const char **);
#define el_isprint(x) ((unsigned char) (x) < 0x80 ? isprint(x) : 1) /* XXXMYSQL: Bug#23097 mysql can't insert korean on mysql prompt. */
#define el_isprint(x) ((unsigned char) (x) < 0x80 ? isprint(x) : 1)
#ifdef DEBUG #ifdef DEBUG
#define EL_ABORT(a) do { \ #define EL_ABORT(a) do { \
......
/* $NetBSD: term.h,v 1.15 2003/09/14 21:48:55 christos Exp $ */ /* $NetBSD: term.h,v 1.19 2008/09/10 15:45:37 christos Exp $ */
/*- /*-
* Copyright (c) 1992, 1993 * Copyright (c) 1992, 1993
...@@ -81,25 +81,6 @@ typedef struct { ...@@ -81,25 +81,6 @@ typedef struct {
#define A_K_EN 5 #define A_K_EN 5
#define A_K_NKEYS 6 #define A_K_NKEYS 6
#ifdef _SUNOS
extern int tgetent(char *, const char *);
extern int tgetflag(char *);
extern int tgetnum(char *);
extern int tputs(const char *, int, int (*)(int));
extern char* tgoto(const char*, int, int);
extern char* tgetstr(char*, char**);
#endif
#if !HAVE_DECL_TGOTO
/*
'tgoto' is not declared in the system header files, this causes
problems on 64-bit systems. The function returns a 64 bit pointer
but caller see it as "int" and it's thus truncated to 32-bit
*/
extern char* tgoto(const char*, int, int);
#endif
protected void term_move_to_line(EditLine *, int); protected void term_move_to_line(EditLine *, int);
protected void term_move_to_char(EditLine *, int); protected void term_move_to_char(EditLine *, int);
protected void term_clear_EOL(EditLine *, int); protected void term_clear_EOL(EditLine *, int);
...@@ -119,10 +100,12 @@ protected void term_end(EditLine *); ...@@ -119,10 +100,12 @@ protected void term_end(EditLine *);
protected void term_get(EditLine *, const char **); protected void term_get(EditLine *, const char **);
protected int term_set(EditLine *, const char *); protected int term_set(EditLine *, const char *);
protected int term_settc(EditLine *, int, const char **); protected int term_settc(EditLine *, int, const char **);
protected int term_gettc(EditLine *, int, char **);
protected int term_telltc(EditLine *, int, const char **); protected int term_telltc(EditLine *, int, const char **);
protected int term_echotc(EditLine *, int, const char **); protected int term_echotc(EditLine *, int, const char **);
protected int term__putc(int); protected void term_writec(EditLine *, int);
protected void term__flush(void); protected int term__putc(EditLine *, int);
protected void term__flush(EditLine *);
/* /*
* Easy access macros * Easy access macros
...@@ -134,6 +117,7 @@ protected void term__flush(void); ...@@ -134,6 +117,7 @@ protected void term__flush(void);
#define EL_CAN_CEOL (EL_FLAGS & TERM_CAN_CEOL) #define EL_CAN_CEOL (EL_FLAGS & TERM_CAN_CEOL)
#define EL_CAN_TAB (EL_FLAGS & TERM_CAN_TAB) #define EL_CAN_TAB (EL_FLAGS & TERM_CAN_TAB)
#define EL_CAN_ME (EL_FLAGS & TERM_CAN_ME) #define EL_CAN_ME (EL_FLAGS & TERM_CAN_ME)
#define EL_CAN_UP (EL_FLAGS & TERM_CAN_UP)
#define EL_HAS_META (EL_FLAGS & TERM_HAS_META) #define EL_HAS_META (EL_FLAGS & TERM_HAS_META)
#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)
......
/* $NetBSD: emacs.c,v 1.19 2004/10/28 21:14:52 dsl Exp $ */ /* $NetBSD: emacs.c,v 1.21 2006/03/06 21:11:56 christos Exp $ */
/*- /*-
* Copyright (c) 1992, 1993 * Copyright (c) 1992, 1993
...@@ -32,7 +32,13 @@ ...@@ -32,7 +32,13 @@
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
#include <config.h> #include "config.h"
#if !defined(lint) && !defined(SCCSID)
#if 0
static char sccsid[] = "@(#)emacs.c 8.1 (Berkeley) 6/4/93";
#else
#endif
#endif /* not lint && not SCCSID */
/* /*
* emacs.c: Emacs functions * emacs.c: Emacs functions
...@@ -45,15 +51,14 @@ ...@@ -45,15 +51,14 @@
*/ */
protected el_action_t protected el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
em_delete_or_list(EditLine *el, int c __attribute__((__unused__))) em_delete_or_list(EditLine *el, int c)
{ {
if (el->el_line.cursor == el->el_line.lastchar) { if (el->el_line.cursor == el->el_line.lastchar) {
/* if I'm at the end */ /* if I'm at the end */
if (el->el_line.cursor == el->el_line.buffer) { if (el->el_line.cursor == el->el_line.buffer) {
/* and the beginning */ /* and the beginning */
term_overwrite(el, STReof, 4); /* then do a EOF */ term_writec(el, c); /* then do an EOF */
term__flush();
return (CC_EOF); return (CC_EOF);
} else { } else {
/* /*
......
#include <stdio.h>
char *fgetln(FILE *stream, size_t *len);
This diff is collapsed.
/* $NetBSD: fgetln.c,v 1.2 2003/12/10 01:30:27 lukem Exp $ */ /* $NetBSD: filecomplete.h,v 1.6 2008/04/29 06:53:01 martin Exp $ */
/*- /*-
* Copyright (c) 1998 The NetBSD Foundation, Inc. * Copyright (c) 1997 The NetBSD Foundation, Inc.
* All rights reserved. * All rights reserved.
* *
* This code is derived from software contributed to The NetBSD Foundation * This code is derived from software contributed to The NetBSD Foundation
* by Christos Zoulas. * by Jaromir Dolecek.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
...@@ -15,13 +15,6 @@ ...@@ -15,13 +15,6 @@
* 2. Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * 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 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
...@@ -35,54 +28,17 @@ ...@@ -35,54 +28,17 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef _FILECOMPLETE_H_
#define _FILECOMPLETE_H_
#include <config.h> int fn_complete(EditLine *,
#include <stdio.h> char *(*)(const char *, int),
#include <stdlib.h> char **(*)(const char *, int, int),
#include <unistd.h> const char *, const char *, const char *(*)(const char *), int,
#include <errno.h> int *, int *, int *, int *);
#include <string.h>
void fn_display_match_list(EditLine *, char **, int, int);
char *fn_tilde_expand(const char *);
char *fn_filename_completion_function(const char *, int);
char * #endif
fgetln(FILE *fp, size_t *len)
{
static char *buf = NULL;
static size_t bufsiz = 0;
char *ptr;
if (buf == NULL) {
bufsiz = BUFSIZ;
if ((buf = malloc(bufsiz)) == NULL)
return NULL;
}
if (fgets(buf, bufsiz, fp) == NULL)
return NULL;
*len = 0;
while ((ptr = strchr(&buf[*len], '\n')) == NULL) {
size_t nbufsiz = bufsiz + BUFSIZ;
char *nbuf = realloc(buf, nbufsiz);
if (nbuf == NULL) {
int oerrno = errno;
free(buf);
errno = oerrno;
buf = NULL;
return NULL;
} else
buf = nbuf;
*len = bufsiz;
if (fgets(&buf[bufsiz], BUFSIZ, fp) == NULL)
return buf;
bufsiz = nbufsiz;
}
*len = (ptr - buf) + 1;
return buf;
}
...@@ -32,7 +32,13 @@ ...@@ -32,7 +32,13 @@
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
#include <config.h> #include "config.h"
#if !defined(lint) && !defined(SCCSID)
#if 0
static char sccsid[] = "@(#)hist.c 8.1 (Berkeley) 6/4/93";
#else
#endif
#endif /* not lint && not SCCSID */
/* /*
* hist.c: History access functions * hist.c: History access functions
......
/* $NetBSD: histedit.h,v 1.25 2003/12/05 13:37:48 lukem Exp $ */ /* $NetBSD: histedit.h,v 1.35 2009/02/05 19:15:44 christos Exp $ */
/*- /*-
* Copyright (c) 1992, 1993 * Copyright (c) 1992, 1993
...@@ -41,11 +41,15 @@ ...@@ -41,11 +41,15 @@
#define _HISTEDIT_H_ #define _HISTEDIT_H_
#define LIBEDIT_MAJOR 2 #define LIBEDIT_MAJOR 2
#define LIBEDIT_MINOR 9 #define LIBEDIT_MINOR 11
#include <sys/types.h> #include <sys/types.h>
#include <stdio.h> #include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
/* /*
* ==== Editing ==== * ==== Editing ====
*/ */
...@@ -88,7 +92,7 @@ void el_reset(EditLine *); ...@@ -88,7 +92,7 @@ void el_reset(EditLine *);
*/ */
const char *el_gets(EditLine *, int *); const char *el_gets(EditLine *, int *);
int el_getc(EditLine *, char *); int el_getc(EditLine *, char *);
void el_push(EditLine *, char *); void el_push(EditLine *, const char *);
/* /*
* Beep! * Beep!
...@@ -105,7 +109,8 @@ int el_parse(EditLine *, int, const char **); ...@@ -105,7 +109,8 @@ int el_parse(EditLine *, int, const char **);
* Low level editline access functions * Low level editline access functions
*/ */
int el_set(EditLine *, int, ...); int el_set(EditLine *, int, ...);
int el_get(EditLine *, int, void *); int el_get(EditLine *, int, ...);
unsigned char _el_fn_complete(EditLine *, int);
/* /*
* el_set/el_get parameters * el_set/el_get parameters
...@@ -128,8 +133,12 @@ int el_get(EditLine *, int, void *); ...@@ -128,8 +133,12 @@ int el_get(EditLine *, int, void *);
#define EL_CLIENTDATA 14 /* , void *); */ #define EL_CLIENTDATA 14 /* , void *); */
#define EL_UNBUFFERED 15 /* , int); */ #define EL_UNBUFFERED 15 /* , int); */
#define EL_PREP_TERM 16 /* , int); */ #define EL_PREP_TERM 16 /* , int); */
#define EL_GETTC 17 /* , const char *, ..., NULL); */
#define EL_GETFP 18 /* , int, FILE **); */
#define EL_SETFP 19 /* , int, FILE *); */
#define EL_REFRESH 20 /* , void); */
#define EL_BUILTIN_GETCFN (NULL) #define EL_BUILTIN_GETCFN (NULL)
/* /*
* Source named file or $PWD/.editrc or $HOME/.editrc * Source named file or $PWD/.editrc or $HOME/.editrc
...@@ -192,6 +201,7 @@ int history(History *, HistEvent *, int, ...); ...@@ -192,6 +201,7 @@ int history(History *, HistEvent *, int, ...);
#define H_CLEAR 19 /* , void); */ #define H_CLEAR 19 /* , void); */
#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); */
/* /*
...@@ -211,4 +221,8 @@ int tok_line(Tokenizer *, const LineInfo *, ...@@ -211,4 +221,8 @@ int tok_line(Tokenizer *, const LineInfo *,
int tok_str(Tokenizer *, const char *, int tok_str(Tokenizer *, const char *,
int *, const char ***); int *, const char ***);
#ifdef __cplusplus
}
#endif
#endif /* _HISTEDIT_H_ */ #endif /* _HISTEDIT_H_ */
/* $NetBSD: history.c,v 1.28 2004/11/27 18:31:45 christos Exp $ */ /* $NetBSD: history.c,v 1.33 2009/02/06 14:40:32 sketch Exp $ */
/*- /*-
* Copyright (c) 1992, 1993 * Copyright (c) 1992, 1993
...@@ -32,7 +32,13 @@ ...@@ -32,7 +32,13 @@
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
#include <config.h> #include "config.h"
#if !defined(lint) && !defined(SCCSID)
#if 0
static char sccsid[] = "@(#)history.c 8.1 (Berkeley) 6/4/93";
#else
#endif
#endif /* not lint && not SCCSID */
/* /*
* hist.c: History access functions * hist.c: History access functions
...@@ -40,7 +46,11 @@ ...@@ -40,7 +46,11 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>
#ifdef HAVE_VIS_H
#include <vis.h> #include <vis.h>
#else
#include "np/vis.h"
#endif
#include <sys/stat.h> #include <sys/stat.h>
static const char hist_cookie[] = "_HiStOrY_V2_\n"; static const char hist_cookie[] = "_HiStOrY_V2_\n";
...@@ -61,6 +71,7 @@ struct history { ...@@ -61,6 +71,7 @@ struct history {
history_gfun_t h_prev; /* Get the previous element */ history_gfun_t h_prev; /* Get the previous element */
history_gfun_t h_curr; /* Get the current element */ history_gfun_t h_curr; /* Get the current element */
history_sfun_t h_set; /* Set the current element */ history_sfun_t h_set; /* Set the current element */
history_sfun_t h_del; /* Set the given element */
history_vfun_t h_clear; /* Clear the history list */ history_vfun_t h_clear; /* Clear the history list */
history_efun_t h_enter; /* Add an element */ history_efun_t h_enter; /* Add an element */
history_efun_t h_add; /* Append to an element */ history_efun_t h_add; /* Append to an element */
...@@ -75,6 +86,7 @@ struct history { ...@@ -75,6 +86,7 @@ struct history {
#define HCLEAR(h, ev) (*(h)->h_clear)((h)->h_ref, ev) #define HCLEAR(h, ev) (*(h)->h_clear)((h)->h_ref, ev)
#define HENTER(h, ev, str) (*(h)->h_enter)((h)->h_ref, ev, str) #define HENTER(h, ev, str) (*(h)->h_enter)((h)->h_ref, ev, str)
#define HADD(h, ev, str) (*(h)->h_add)((h)->h_ref, ev, str) #define HADD(h, ev, str) (*(h)->h_add)((h)->h_ref, ev, str)
#define HDEL(h, ev, n) (*(h)->h_del)((h)->h_ref, ev, n)
#define h_strdup(a) strdup(a) #define h_strdup(a) strdup(a)
#define h_malloc(a) malloc(a) #define h_malloc(a) malloc(a)
...@@ -122,16 +134,18 @@ typedef struct history_t { ...@@ -122,16 +134,18 @@ typedef struct history_t {
#define H_UNIQUE 1 /* Store only unique elements */ #define H_UNIQUE 1 /* Store only unique elements */
} history_t; } history_t;
private int history_def_first(ptr_t, HistEvent *);
private int history_def_last(ptr_t, HistEvent *);
private int history_def_next(ptr_t, HistEvent *); private int history_def_next(ptr_t, HistEvent *);
private int history_def_first(ptr_t, HistEvent *);
private int history_def_prev(ptr_t, HistEvent *); private int history_def_prev(ptr_t, HistEvent *);
private int history_def_last(ptr_t, HistEvent *);
private int history_def_curr(ptr_t, HistEvent *); private int history_def_curr(ptr_t, HistEvent *);
private int history_def_set(ptr_t, HistEvent *, const int n); private int history_def_set(ptr_t, HistEvent *, const int);
private void history_def_clear(ptr_t, HistEvent *);
private int history_def_enter(ptr_t, HistEvent *, const char *); private int history_def_enter(ptr_t, HistEvent *, const char *);
private int history_def_add(ptr_t, HistEvent *, const char *); private int history_def_add(ptr_t, HistEvent *, const char *);
private int history_def_del(ptr_t, HistEvent *, const int);
private int history_def_init(ptr_t *, HistEvent *, int); private int history_def_init(ptr_t *, HistEvent *, int);
private void history_def_clear(ptr_t, HistEvent *);
private int history_def_insert(history_t *, HistEvent *, const char *); private int history_def_insert(history_t *, HistEvent *, const char *);
private void history_def_delete(history_t *, HistEvent *, hentry_t *); private void history_def_delete(history_t *, HistEvent *, hentry_t *);
...@@ -353,6 +367,24 @@ history_def_add(ptr_t p, HistEvent *ev, const char *str) ...@@ -353,6 +367,24 @@ history_def_add(ptr_t p, HistEvent *ev, const char *str)
} }
/* history_def_del():
* Delete element hp of the h list
*/
/* ARGSUSED */
private int
history_def_del(ptr_t p, HistEvent *ev __attribute__((__unused__)),
const int num)
{
history_t *h = (history_t *) p;
if (history_def_set(h, ev, num) != 0)
return (-1);
ev->str = strdup(h->cursor->ev.str);
ev->num = h->cursor->ev.num;
history_def_delete(h, ev, h->cursor);
return (0);
}
/* history_def_delete(): /* history_def_delete():
* Delete element hp of the h list * Delete element hp of the h list
*/ */
...@@ -364,6 +396,8 @@ history_def_delete(history_t *h, ...@@ -364,6 +396,8 @@ history_def_delete(history_t *h,
HistEventPrivate *evp = (void *)&hp->ev; HistEventPrivate *evp = (void *)&hp->ev;
if (hp == &h->list) if (hp == &h->list)
abort(); abort();
if (h->cursor == hp)
h->cursor = hp->prev;
hp->prev->next = hp->next; hp->prev->next = hp->next;
hp->next->prev = hp->prev; hp->next->prev = hp->prev;
h_free((ptr_t) evp->str); h_free((ptr_t) evp->str);
...@@ -497,6 +531,7 @@ history_init(void) ...@@ -497,6 +531,7 @@ history_init(void)
h->h_clear = history_def_clear; h->h_clear = history_def_clear;
h->h_enter = history_def_enter; h->h_enter = history_def_enter;
h->h_add = history_def_add; h->h_add = history_def_add;
h->h_del = history_def_del;
return (h); return (h);
} }
...@@ -512,6 +547,8 @@ history_end(History *h) ...@@ -512,6 +547,8 @@ history_end(History *h)
if (h->h_next == history_def_next) if (h->h_next == history_def_next)
history_def_clear(h->h_ref, &ev); history_def_clear(h->h_ref, &ev);
h_free(h->h_ref);
h_free(h);
} }
...@@ -597,7 +634,7 @@ history_set_fun(History *h, History *nh) ...@@ -597,7 +634,7 @@ history_set_fun(History *h, History *nh)
if (nh->h_first == NULL || nh->h_next == NULL || nh->h_last == NULL || if (nh->h_first == NULL || nh->h_next == NULL || nh->h_last == NULL ||
nh->h_prev == NULL || nh->h_curr == NULL || nh->h_set == NULL || nh->h_prev == NULL || nh->h_curr == NULL || nh->h_set == NULL ||
nh->h_enter == NULL || nh->h_add == NULL || nh->h_clear == NULL || nh->h_enter == NULL || nh->h_add == NULL || nh->h_clear == NULL ||
nh->h_ref == NULL) { nh->h_del == NULL || nh->h_ref == NULL) {
if (h->h_next != history_def_next) { if (h->h_next != history_def_next) {
history_def_init(&h->h_ref, &ev, 0); history_def_init(&h->h_ref, &ev, 0);
h->h_first = history_def_first; h->h_first = history_def_first;
...@@ -609,6 +646,7 @@ history_set_fun(History *h, History *nh) ...@@ -609,6 +646,7 @@ history_set_fun(History *h, History *nh)
h->h_clear = history_def_clear; h->h_clear = history_def_clear;
h->h_enter = history_def_enter; h->h_enter = history_def_enter;
h->h_add = history_def_add; h->h_add = history_def_add;
h->h_del = history_def_del;
} }
return (-1); return (-1);
} }
...@@ -625,6 +663,7 @@ history_set_fun(History *h, History *nh) ...@@ -625,6 +663,7 @@ history_set_fun(History *h, History *nh)
h->h_clear = nh->h_clear; h->h_clear = nh->h_clear;
h->h_enter = nh->h_enter; h->h_enter = nh->h_enter;
h->h_add = nh->h_add; h->h_add = nh->h_add;
h->h_del = nh->h_del;
return (0); return (0);
} }
...@@ -676,8 +715,8 @@ history_load(History *h, const char *fname) ...@@ -676,8 +715,8 @@ history_load(History *h, const char *fname)
(void) strunvis(ptr, line); (void) strunvis(ptr, line);
line[sz] = c; line[sz] = c;
if (HENTER(h, &ev, ptr) == -1) { if (HENTER(h, &ev, ptr) == -1) {
i = -1; i = -1;
goto oomem; goto oomem;
} }
} }
oomem: oomem:
...@@ -841,6 +880,10 @@ history(History *h, HistEvent *ev, int fun, ...) ...@@ -841,6 +880,10 @@ history(History *h, HistEvent *ev, int fun, ...)
retval = HADD(h, ev, str); retval = HADD(h, ev, str);
break; break;
case H_DEL:
retval = HDEL(h, ev, va_arg(va, const int));
break;
case H_ENTER: case H_ENTER:
str = va_arg(va, const char *); str = va_arg(va, const char *);
if ((retval = HENTER(h, ev, str)) != -1) if ((retval = HENTER(h, ev, str)) != -1)
...@@ -925,6 +968,7 @@ history(History *h, HistEvent *ev, int fun, ...) ...@@ -925,6 +968,7 @@ history(History *h, HistEvent *ev, int fun, ...)
hf.h_clear = va_arg(va, history_vfun_t); hf.h_clear = va_arg(va, history_vfun_t);
hf.h_enter = va_arg(va, history_efun_t); hf.h_enter = va_arg(va, history_efun_t);
hf.h_add = va_arg(va, history_efun_t); hf.h_add = va_arg(va, history_efun_t);
hf.h_del = va_arg(va, history_sfun_t);
if ((retval = history_set_fun(h, &hf)) == -1) if ((retval = history_set_fun(h, &hf)) == -1)
he_seterrev(ev, _HE_PARAM_MISSING); he_seterrev(ev, _HE_PARAM_MISSING);
......
/* $NetBSD: key.c,v 1.15 2003/10/18 23:48:42 christos Exp $ */ /* $NetBSD: key.c,v 1.19 2006/03/23 20:22:51 christos Exp $ */
/*- /*-
* Copyright (c) 1992, 1993 * Copyright (c) 1992, 1993
...@@ -32,14 +32,20 @@ ...@@ -32,14 +32,20 @@
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
#include <config.h> #include "config.h"
#if !defined(lint) && !defined(SCCSID)
#if 0
static char sccsid[] = "@(#)key.c 8.1 (Berkeley) 6/4/93";
#else
#endif
#endif /* not lint && not SCCSID */
/* /*
* key.c: This module contains the procedures for maintaining * key.c: This module contains the procedures for maintaining
* the extended-key map. * the extended-key map.
* *
* An extended-key (key) is a sequence of keystrokes introduced * An extended-key (key) is a sequence of keystrokes introduced
* with an sequence introducer and consisting of an arbitrary * with a sequence introducer and consisting of an arbitrary
* number of characters. This module maintains a map (the el->el_key.map) * number of characters. This module maintains a map (the el->el_key.map)
* to convert these extended-key sequences into input strs * to convert these extended-key sequences into input strs
* (XK_STR), editor functions (XK_CMD), or unix commands (XK_EXE). * (XK_STR), editor functions (XK_CMD), or unix commands (XK_EXE).
...@@ -78,12 +84,12 @@ private int node_trav(EditLine *, key_node_t *, char *, ...@@ -78,12 +84,12 @@ private int node_trav(EditLine *, key_node_t *, char *,
private int node__try(EditLine *, key_node_t *, const char *, private int node__try(EditLine *, key_node_t *, const char *,
key_value_t *, int); key_value_t *, int);
private key_node_t *node__get(int); private key_node_t *node__get(int);
private void node__free(key_node_t *);
private void node__put(EditLine *, key_node_t *); private void node__put(EditLine *, key_node_t *);
private int node__delete(EditLine *, key_node_t **, const char *); private int node__delete(EditLine *, key_node_t **, const char *);
private int node_lookup(EditLine *, const char *, key_node_t *, private int node_lookup(EditLine *, const char *, key_node_t *,
int); int);
private int node_enum(EditLine *, key_node_t *, int); private int node_enum(EditLine *, key_node_t *, int);
private int key__decode_char(char *, int, int);
#define KEY_BUFSIZ EL_BUFSIZ #define KEY_BUFSIZ EL_BUFSIZ
...@@ -103,7 +109,6 @@ key_init(EditLine *el) ...@@ -103,7 +109,6 @@ key_init(EditLine *el)
return (0); return (0);
} }
/* key_end(): /* key_end():
* Free the key maps * Free the key maps
*/ */
...@@ -113,8 +118,7 @@ key_end(EditLine *el) ...@@ -113,8 +118,7 @@ key_end(EditLine *el)
el_free((ptr_t) el->el_key.buf); el_free((ptr_t) el->el_key.buf);
el->el_key.buf = NULL; el->el_key.buf = NULL;
/* XXX: provide a function to clear the keys */ node__free(el->el_key.map);
el->el_key.map = NULL;
} }
...@@ -443,7 +447,7 @@ node__put(EditLine *el, key_node_t *ptr) ...@@ -443,7 +447,7 @@ node__put(EditLine *el, key_node_t *ptr)
/* node__get(): /* node__get():
* Returns pointer to an key_node_t for ch. * Returns pointer to a key_node_t for ch.
*/ */
private key_node_t * private key_node_t *
node__get(int ch) node__get(int ch)
...@@ -461,7 +465,15 @@ node__get(int ch) ...@@ -461,7 +465,15 @@ node__get(int ch)
return (ptr); return (ptr);
} }
private void
node__free(key_node_t *k)
{
if (k == NULL)
return;
node__free(k->sibling);
node__free(k->next);
el_free((ptr_t) k);
}
/* node_lookup(): /* node_lookup():
* look for the str starting at node ptr. * look for the str starting at node ptr.
...@@ -483,7 +495,7 @@ node_lookup(EditLine *el, const char *str, key_node_t *ptr, int cnt) ...@@ -483,7 +495,7 @@ node_lookup(EditLine *el, const char *str, key_node_t *ptr, int cnt)
/* If match put this char into el->el_key.buf. Recurse */ /* If match put this char into el->el_key.buf. Recurse */
if (ptr->ch == *str) { if (ptr->ch == *str) {
/* match found */ /* match found */
ncnt = key__decode_char(el->el_key.buf, cnt, ncnt = key__decode_char(el->el_key.buf, KEY_BUFSIZ, cnt,
(unsigned char) ptr->ch); (unsigned char) ptr->ch);
if (ptr->next != NULL) if (ptr->next != NULL)
/* not yet at leaf */ /* not yet at leaf */
...@@ -537,7 +549,8 @@ node_enum(EditLine *el, key_node_t *ptr, int cnt) ...@@ -537,7 +549,8 @@ node_enum(EditLine *el, key_node_t *ptr, int cnt)
return (-1); return (-1);
} }
/* put this char at end of str */ /* put this char at end of str */
ncnt = key__decode_char(el->el_key.buf, cnt, (unsigned char) ptr->ch); ncnt = key__decode_char(el->el_key.buf, KEY_BUFSIZ, cnt,
(unsigned char)ptr->ch);
if (ptr->next == NULL) { if (ptr->next == NULL) {
/* print this key and function */ /* print this key and function */
el->el_key.buf[ncnt + 1] = '"'; el->el_key.buf[ncnt + 1] = '"';
...@@ -568,9 +581,10 @@ key_kprint(EditLine *el, const char *key, key_value_t *val, int ntype) ...@@ -568,9 +581,10 @@ key_kprint(EditLine *el, const char *key, key_value_t *val, int ntype)
switch (ntype) { switch (ntype) {
case XK_STR: case XK_STR:
case XK_EXE: case XK_EXE:
(void) fprintf(el->el_outfile, fmt, key, (void) key__decode_str(val->str, unparsbuf,
key__decode_str(val->str, unparsbuf, sizeof(unparsbuf),
ntype == XK_STR ? "\"\"" : "[]")); ntype == XK_STR ? "\"\"" : "[]");
(void) fprintf(el->el_outfile, fmt, key, unparsbuf);
break; break;
case XK_CMD: case XK_CMD:
for (fp = el->el_map.help; fp->name; fp++) for (fp = el->el_map.help; fp->name; fp++)
...@@ -595,83 +609,97 @@ key_kprint(EditLine *el, const char *key, key_value_t *val, int ntype) ...@@ -595,83 +609,97 @@ key_kprint(EditLine *el, const char *key, key_value_t *val, int ntype)
} }
#define ADDC(c) \
if (b < eb) \
*b++ = c; \
else \
b++
/* key__decode_char(): /* key__decode_char():
* Put a printable form of char in buf. * Put a printable form of char in buf.
*/ */
private int protected int
key__decode_char(char *buf, int cnt, int ch) key__decode_char(char *buf, int cnt, int off, int ch)
{ {
char *sb = buf + off;
char *eb = buf + cnt;
char *b = sb;
if (ch == 0) { if (ch == 0) {
buf[cnt++] = '^'; ADDC('^');
buf[cnt] = '@'; ADDC('@');
return (cnt); return b - sb;
} }
if (iscntrl(ch)) { if (iscntrl(ch)) {
buf[cnt++] = '^'; ADDC('^');
if (ch == '\177') if (ch == '\177')
buf[cnt] = '?'; ADDC('?');
else else
buf[cnt] = ch | 0100; ADDC(ch | 0100);
} else if (ch == '^') { } else if (ch == '^') {
buf[cnt++] = '\\'; ADDC('\\');
buf[cnt] = '^'; ADDC('^');
} else if (ch == '\\') { } else if (ch == '\\') {
buf[cnt++] = '\\'; ADDC('\\');
buf[cnt] = '\\'; ADDC('\\');
} else if (ch == ' ' || (el_isprint(ch) && !isspace(ch))) { } else if (ch == ' ' || (el_isprint(ch) && !isspace(ch))) {
buf[cnt] = ch; ADDC(ch);
} else { } else {
buf[cnt++] = '\\'; ADDC('\\');
buf[cnt++] = (((unsigned int) ch >> 6) & 7) + '0'; ADDC((((unsigned int) ch >> 6) & 7) + '0');
buf[cnt++] = (((unsigned int) ch >> 3) & 7) + '0'; ADDC((((unsigned int) ch >> 3) & 7) + '0');
buf[cnt] = (ch & 7) + '0'; ADDC((ch & 7) + '0');
} }
return (cnt); return b - sb;
} }
/* key__decode_str(): /* key__decode_str():
* Make a printable version of the ey * Make a printable version of the ey
*/ */
protected char * protected int
key__decode_str(const char *str, char *buf, const char *sep) key__decode_str(const char *str, char *buf, int len, const char *sep)
{ {
char *b; char *b = buf, *eb = b + len;
const char *p; const char *p;
b = buf; b = buf;
if (sep[0] != '\0') if (sep[0] != '\0') {
*b++ = sep[0]; ADDC(sep[0]);
if (*str == 0) { }
*b++ = '^'; if (*str == '\0') {
*b++ = '@'; ADDC('^');
if (sep[0] != '\0' && sep[1] != '\0') ADDC('@');
*b++ = sep[1]; if (sep[0] != '\0' && sep[1] != '\0') {
*b++ = 0; ADDC(sep[1]);
return (buf); }
goto done;
} }
for (p = str; *p != 0; p++) { for (p = str; *p != 0; p++) {
if (iscntrl((unsigned char) *p)) { if (iscntrl((unsigned char) *p)) {
*b++ = '^'; ADDC('^');
if (*p == '\177') if (*p == '\177') {
*b++ = '?'; ADDC('?');
else } else {
*b++ = *p | 0100; ADDC(*p | 0100);
}
} else if (*p == '^' || *p == '\\') { } else if (*p == '^' || *p == '\\') {
*b++ = '\\'; ADDC('\\');
*b++ = *p; ADDC(*p);
} else if (*p == ' ' || (el_isprint((unsigned char) *p) && } else if (*p == ' ' || (el_isprint((unsigned char) *p) &&
!isspace((unsigned char) *p))) { !isspace((unsigned char) *p))) {
*b++ = *p; ADDC(*p);
} else { } else {
*b++ = '\\'; ADDC('\\');
*b++ = (((unsigned int) *p >> 6) & 7) + '0'; ADDC((((unsigned int) *p >> 6) & 7) + '0');
*b++ = (((unsigned int) *p >> 3) & 7) + '0'; ADDC((((unsigned int) *p >> 3) & 7) + '0');
*b++ = (*p & 7) + '0'; ADDC((*p & 7) + '0');
} }
} }
if (sep[0] != '\0' && sep[1] != '\0') if (sep[0] != '\0' && sep[1] != '\0') {
*b++ = sep[1]; ADDC(sep[1]);
*b++ = 0; }
return (buf); /* should check for overflow */ done:
ADDC('\0');
if (b - buf >= len)
buf[len - 1] = '\0';
return b - buf;
} }
/* $NetBSD: key.h,v 1.8 2003/08/07 16:44:32 agc Exp $ */ /* $NetBSD: key.h,v 1.10 2006/03/23 20:22:51 christos Exp $ */
/*- /*-
* Copyright (c) 1992, 1993 * Copyright (c) 1992, 1993
...@@ -74,6 +74,8 @@ protected int key_delete(EditLine *, const char *); ...@@ -74,6 +74,8 @@ protected int key_delete(EditLine *, const char *);
protected void key_print(EditLine *, const char *); protected void key_print(EditLine *, const char *);
protected void key_kprint(EditLine *, const char *, key_value_t *, protected void key_kprint(EditLine *, const char *, key_value_t *,
int); int);
protected char *key__decode_str(const char *, char *, const char *); protected int key__decode_str(const char *, char *, int,
const char *);
protected int key__decode_char(char *, int, int, int);
#endif /* _h_el_key */ #endif /* _h_el_key */
/* $NetBSD: term.h,v 1.12 2001/01/04 15:56:32 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Christos Zoulas of Cornell University.
*
* 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 University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University 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 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.
*
* @(#)term.h 8.1 (Berkeley) 6/4/93
*/
/*
* el.term.h: Termcap header
*/
#ifndef _h_el_term
#define _h_el_term
#include "histedit.h"
typedef struct { /* Symbolic function key bindings */
const char *name; /* name of the key */
int key; /* Index in termcap table */
key_value_t fun; /* Function bound to it */
int type; /* Type of function */
} fkey_t;
typedef struct {
coord_t t_size; /* # lines and cols */
int t_flags;
#define TERM_CAN_INSERT 0x001 /* Has insert cap */
#define TERM_CAN_DELETE 0x002 /* Has delete cap */
#define TERM_CAN_CEOL 0x004 /* Has CEOL cap */
#define TERM_CAN_TAB 0x008 /* Can use tabs */
#define TERM_CAN_ME 0x010 /* Can turn all attrs. */
#define TERM_CAN_UP 0x020 /* Can move up */
#define TERM_HAS_META 0x040 /* Has a meta key */
#define TERM_HAS_AUTO_MARGINS 0x080 /* Has auto margins */
#define TERM_HAS_MAGIC_MARGINS 0x100 /* Has magic margins */
char *t_buf; /* Termcap buffer */
int t_loc; /* location used */
char **t_str; /* termcap strings */
int *t_val; /* termcap values */
char *t_cap; /* Termcap buffer */
fkey_t *t_fkey; /* Array of keys */
} el_term_t;
/*
* fKey indexes
*/
#define A_K_DN 0
#define A_K_UP 1
#define A_K_LT 2
#define A_K_RT 3
#define A_K_HO 4
#define A_K_EN 5
#define A_K_NKEYS 6
protected void term_move_to_line(EditLine *, int);
protected void term_move_to_char(EditLine *, int);
protected void term_clear_EOL(EditLine *, int);
protected void term_overwrite(EditLine *, const char *, int);
protected void term_insertwrite(EditLine *, char *, int);
protected void term_deletechars(EditLine *, int);
protected void term_clear_screen(EditLine *);
protected void term_beep(EditLine *);
protected int term_change_size(EditLine *, int, int);
protected int term_get_size(EditLine *, int *, int *);
protected int term_init(EditLine *);
protected void term_bind_arrow(EditLine *);
protected void term_print_arrow(EditLine *, const char *);
protected int term_clear_arrow(EditLine *, const char *);
protected int term_set_arrow(EditLine *, const char *, key_value_t *, int);
protected void term_end(EditLine *);
protected int term_set(EditLine *, const char *);
protected int term_settc(EditLine *, int, const char **);
protected int term_telltc(EditLine *, int, const char **);
protected int term_echotc(EditLine *, int, const char **);
protected int term__putc(int);
protected void term__flush(void);
/*
* Easy access macros
*/
#define EL_FLAGS (el)->el_term.t_flags
#define EL_CAN_INSERT (EL_FLAGS & TERM_CAN_INSERT)
#define EL_CAN_DELETE (EL_FLAGS & TERM_CAN_DELETE)
#define EL_CAN_CEOL (EL_FLAGS & TERM_CAN_CEOL)
#define EL_CAN_TAB (EL_FLAGS & TERM_CAN_TAB)
#define EL_CAN_ME (EL_FLAGS & TERM_CAN_ME)
#define EL_HAS_META (EL_FLAGS & TERM_HAS_META)
#define EL_HAS_AUTO_MARGINS (EL_FLAGS & TERM_HAS_AUTO_MARGINS)
#define EL_HAS_MAGIC_MARGINS (EL_FLAGS & TERM_HAS_MAGIC_MARGINS)
#endif /* _h_el_term */
#!/bin/sh - #!/bin/sh -
# $NetBSD: makelist,v 1.8 2003/03/10 21:21:10 christos Exp $ # $NetBSD: makelist,v 1.11 2005/10/22 16:45:03 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.
...@@ -15,11 +15,7 @@ ...@@ -15,11 +15,7 @@
# 2. Redistributions in binary form must reproduce the above copyright # 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the # notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution. # documentation and/or other materials provided with the distribution.
# 3. All advertising materials mentioning features or use of this software # 3. Neither the name of the University nor the names of its contributors
# must display the following acknowledgement:
# This product includes software developed by the University of
# California, Berkeley and its contributors.
# 4. Neither the name of the University nor the names of its contributors
# may be used to endorse or promote products derived from this software # may be used to endorse or promote products derived from this software
# without specific prior written permission. # without specific prior written permission.
# #
...@@ -68,6 +64,7 @@ case $FLAG in ...@@ -68,6 +64,7 @@ case $FLAG in
/\(\):/ { /\(\):/ {
pr = substr($2, 1, 2); pr = substr($2, 1, 2);
if (pr == "vi" || pr == "em" || pr == "ed") { if (pr == "vi" || pr == "em" || pr == "ed") {
# XXXMYSQL: support CRLF
name = substr($2, 1, index($2,"(") - 1); name = substr($2, 1, index($2,"(") - 1);
# #
# 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
...@@ -87,7 +84,7 @@ case $FLAG in ...@@ -87,7 +84,7 @@ case $FLAG in
cat $FILES | $AWK ' cat $FILES | $AWK '
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 \"sys.h\"\n#include \"el.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_";
...@@ -97,6 +94,7 @@ case $FLAG in ...@@ -97,6 +94,7 @@ case $FLAG in
/\(\):/ { /\(\):/ {
pr = substr($2, 1, 2); pr = substr($2, 1, 2);
if (pr == "vi" || pr == "em" || pr == "ed") { if (pr == "vi" || pr == "em" || pr == "ed") {
# XXXMYSQL: support CRLF
name = substr($2, 1, index($2,"(") - 1); name = substr($2, 1, index($2,"(") - 1);
uname = ""; uname = "";
fname = ""; fname = "";
...@@ -117,13 +115,13 @@ case $FLAG in ...@@ -117,13 +115,13 @@ case $FLAG in
printf(" \""); printf(" \"");
for (i = 2; i < NF; i++) for (i = 2; i < NF; i++)
printf("%s ", $i); printf("%s ", $i);
sub("\r", "", $i); # XXXMYSQL: support CRLF
sub("\r", "", $i);
printf("%s\" },\n", $i); printf("%s\" },\n", $i);
ok = 0; ok = 0;
} }
} }
END { END {
printf(" { NULL, 0, NULL }\n");
printf("};\n"); printf("};\n");
printf("\nprotected const el_bindings_t* help__get()"); printf("\nprotected const el_bindings_t* help__get()");
printf("{ return el_func_help; }\n"); printf("{ return el_func_help; }\n");
...@@ -144,6 +142,7 @@ case $FLAG in ...@@ -144,6 +142,7 @@ case $FLAG in
# generate fcns.h from various .h files # generate fcns.h from various .h files
# #
# XXXMYSQL: use portable tr syntax
-fh) -fh)
cat $FILES | $AWK '/el_action_t/ { print $3 }' | \ cat $FILES | $AWK '/el_action_t/ { print $3 }' | \
sort | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ | $AWK ' sort | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ | $AWK '
...@@ -170,7 +169,7 @@ case $FLAG in ...@@ -170,7 +169,7 @@ case $FLAG in
cat $FILES | $AWK '/el_action_t/ { print $3 }' | sort | $AWK ' cat $FILES | $AWK '/el_action_t/ { print $3 }' | sort | $AWK '
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 \"sys.h\"\n#include \"el.h\"\n");
printf("private const el_func_t el_func[] = {"); printf("private const el_func_t el_func[] = {");
maxlen = 80; maxlen = 80;
needn = 1; needn = 1;
...@@ -220,6 +219,7 @@ case $FLAG in ...@@ -220,6 +219,7 @@ case $FLAG in
/\(\):/ { /\(\):/ {
pr = substr($2, 1, 2); pr = substr($2, 1, 2);
if (pr == "vi" || pr == "em" || pr == "ed") { if (pr == "vi" || pr == "em" || pr == "ed") {
# XXXMYSQL: support CRLF
name = substr($2, 1, index($2, "(") - 1); name = substr($2, 1, index($2, "(") - 1);
fname = ""; fname = "";
for (i = 1; i <= length(name); i++) { for (i = 1; i <= length(name); i++) {
......
/* $NetBSD: map.c,v 1.20 2004/08/13 12:10:39 mycroft Exp $ */ /* $NetBSD: map.c,v 1.24 2006/04/09 01:36:51 christos Exp $ */
/*- /*-
* Copyright (c) 1992, 1993 * Copyright (c) 1992, 1993
...@@ -32,7 +32,13 @@ ...@@ -32,7 +32,13 @@
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
#include <config.h> #include "config.h"
#if !defined(lint) && !defined(SCCSID)
#if 0
static char sccsid[] = "@(#)map.c 8.1 (Berkeley) 6/4/93";
#else
#endif
#endif /* not lint && not SCCSID */
/* /*
* map.c: Editor function definitions * map.c: Editor function definitions
...@@ -1118,11 +1124,12 @@ private void ...@@ -1118,11 +1124,12 @@ private void
map_print_key(EditLine *el, el_action_t *map, const char *in) map_print_key(EditLine *el, el_action_t *map, const char *in)
{ {
char outbuf[EL_BUFSIZ]; char outbuf[EL_BUFSIZ];
el_bindings_t *bp; el_bindings_t *bp, *ep;
if (in[0] == '\0' || in[1] == '\0') { if (in[0] == '\0' || in[1] == '\0') {
(void) key__decode_str(in, outbuf, ""); (void) key__decode_str(in, outbuf, sizeof(outbuf), "");
for (bp = el->el_map.help; bp->name != NULL; bp++) ep = &el->el_map.help[el->el_map.nfunc];
for (bp = el->el_map.help; bp < ep; bp++)
if (bp->func == map[(unsigned char) *in]) { if (bp->func == map[(unsigned char) *in]) {
(void) fprintf(el->el_outfile, (void) fprintf(el->el_outfile,
"%s\t->\t%s\n", outbuf, bp->name); "%s\t->\t%s\n", outbuf, bp->name);
...@@ -1139,7 +1146,7 @@ map_print_key(EditLine *el, el_action_t *map, const char *in) ...@@ -1139,7 +1146,7 @@ map_print_key(EditLine *el, el_action_t *map, const char *in)
private void private void
map_print_some_keys(EditLine *el, el_action_t *map, int first, int last) map_print_some_keys(EditLine *el, el_action_t *map, int first, int last)
{ {
el_bindings_t *bp; el_bindings_t *bp, *ep;
char firstbuf[2], lastbuf[2]; char firstbuf[2], lastbuf[2];
char unparsbuf[EL_BUFSIZ], extrabuf[EL_BUFSIZ]; char unparsbuf[EL_BUFSIZ], extrabuf[EL_BUFSIZ];
...@@ -1148,39 +1155,47 @@ map_print_some_keys(EditLine *el, el_action_t *map, int first, int last) ...@@ -1148,39 +1155,47 @@ map_print_some_keys(EditLine *el, el_action_t *map, int first, int last)
lastbuf[0] = last; lastbuf[0] = last;
lastbuf[1] = 0; lastbuf[1] = 0;
if (map[first] == ED_UNASSIGNED) { if (map[first] == ED_UNASSIGNED) {
if (first == last) if (first == last) {
(void) key__decode_str(firstbuf, unparsbuf,
sizeof(unparsbuf), STRQQ);
(void) fprintf(el->el_outfile, (void) fprintf(el->el_outfile,
"%-15s-> is undefined\n", "%-15s-> is undefined\n", unparsbuf);
key__decode_str(firstbuf, unparsbuf, STRQQ)); }
return; return;
} }
for (bp = el->el_map.help; bp->name != NULL; bp++) { ep = &el->el_map.help[el->el_map.nfunc];
for (bp = el->el_map.help; bp < ep; bp++) {
if (bp->func == map[first]) { if (bp->func == map[first]) {
if (first == last) { if (first == last) {
(void) key__decode_str(firstbuf, unparsbuf,
sizeof(unparsbuf), STRQQ);
(void) fprintf(el->el_outfile, "%-15s-> %s\n", (void) fprintf(el->el_outfile, "%-15s-> %s\n",
key__decode_str(firstbuf, unparsbuf, STRQQ), unparsbuf, bp->name);
bp->name);
} else { } else {
(void) key__decode_str(firstbuf, unparsbuf,
sizeof(unparsbuf), STRQQ);
(void) key__decode_str(lastbuf, extrabuf,
sizeof(extrabuf), STRQQ);
(void) fprintf(el->el_outfile, (void) fprintf(el->el_outfile,
"%-4s to %-7s-> %s\n", "%-4s to %-7s-> %s\n",
key__decode_str(firstbuf, unparsbuf, STRQQ), unparsbuf, extrabuf, bp->name);
key__decode_str(lastbuf, extrabuf, STRQQ),
bp->name);
} }
return; return;
} }
} }
#ifdef MAP_DEBUG #ifdef MAP_DEBUG
if (map == el->el_map.key) { if (map == el->el_map.key) {
(void) key__decode_str(firstbuf, unparsbuf,
sizeof(unparsbuf), STRQQ);
(void) fprintf(el->el_outfile, (void) fprintf(el->el_outfile,
"BUG!!! %s isn't bound to anything.\n", "BUG!!! %s isn't bound to anything.\n", unparsbuf);
key__decode_str(firstbuf, unparsbuf, STRQQ));
(void) fprintf(el->el_outfile, "el->el_map.key[%d] == %d\n", (void) fprintf(el->el_outfile, "el->el_map.key[%d] == %d\n",
first, el->el_map.key[first]); first, el->el_map.key[first]);
} else { } else {
(void) key__decode_str(firstbuf, unparsbuf,
sizeof(unparsbuf), STRQQ);
(void) fprintf(el->el_outfile, (void) fprintf(el->el_outfile,
"BUG!!! %s isn't bound to anything.\n", "BUG!!! %s isn't bound to anything.\n", unparsbuf);
key__decode_str(firstbuf, unparsbuf, STRQQ));
(void) fprintf(el->el_outfile, "el->el_map.alt[%d] == %d\n", (void) fprintf(el->el_outfile, "el->el_map.alt[%d] == %d\n",
first, el->el_map.alt[first]); first, el->el_map.alt[first]);
} }
...@@ -1237,7 +1252,7 @@ map_bind(EditLine *el, int argc, const char **argv) ...@@ -1237,7 +1252,7 @@ map_bind(EditLine *el, int argc, const char **argv)
char outbuf[EL_BUFSIZ]; char outbuf[EL_BUFSIZ];
const char *in = NULL; const char *in = NULL;
char *out = NULL; char *out = NULL;
el_bindings_t *bp; el_bindings_t *bp, *ep;
int cmd; int cmd;
int key; int key;
...@@ -1279,8 +1294,8 @@ map_bind(EditLine *el, int argc, const char **argv) ...@@ -1279,8 +1294,8 @@ map_bind(EditLine *el, int argc, const char **argv)
return (0); return (0);
case 'l': case 'l':
for (bp = el->el_map.help; bp->name != NULL; ep = &el->el_map.help[el->el_map.nfunc];
bp++) for (bp = el->el_map.help; bp < ep; bp++)
(void) fprintf(el->el_outfile, (void) fprintf(el->el_outfile,
"%s\n\t%s\n", "%s\n\t%s\n",
bp->name, bp->description); bp->name, bp->description);
...@@ -1367,7 +1382,7 @@ map_bind(EditLine *el, int argc, const char **argv) ...@@ -1367,7 +1382,7 @@ map_bind(EditLine *el, int argc, const char **argv)
break; break;
default: default:
EL_ABORT((el->el_errfile, "Bad XK_ type\n", ntype)); EL_ABORT((el->el_errfile, "Bad XK_ type %d\n", ntype));
break; break;
} }
return (0); return (0);
...@@ -1381,7 +1396,7 @@ protected int ...@@ -1381,7 +1396,7 @@ protected int
map_addfunc(EditLine *el, const char *name, const char *help, el_func_t func) map_addfunc(EditLine *el, const char *name, const char *help, el_func_t func)
{ {
void *p; void *p;
int nf = el->el_map.nfunc + 2; int nf = el->el_map.nfunc + 1;
if (name == NULL || help == NULL || func == NULL) if (name == NULL || help == NULL || func == NULL)
return (-1); return (-1);
...@@ -1400,7 +1415,6 @@ map_addfunc(EditLine *el, const char *name, const char *help, el_func_t func) ...@@ -1400,7 +1415,6 @@ map_addfunc(EditLine *el, const char *name, const char *help, el_func_t func)
el->el_map.help[nf].name = name; el->el_map.help[nf].name = name;
el->el_map.help[nf].func = nf; el->el_map.help[nf].func = nf;
el->el_map.help[nf].description = help; el->el_map.help[nf].description = help;
el->el_map.help[++nf].name = NULL;
el->el_map.nfunc++; el->el_map.nfunc++;
return (0); return (0);
......
/* $NetBSD: fgetln.c,v 1.1.1.1 1999/04/12 07:43:21 crooksa Exp $ */ /* $NetBSD: fgetln.c,v 1.9 2008/04/29 06:53:03 martin Exp $ */
/*- /*-
* Copyright (c) 1998 The NetBSD Foundation, Inc. * Copyright (c) 1998 The NetBSD Foundation, Inc.
...@@ -15,13 +15,6 @@ ...@@ -15,13 +15,6 @@
* 2. Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * 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 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
...@@ -36,17 +29,24 @@ ...@@ -36,17 +29,24 @@
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifdef HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#else
#include "config.h" #include "config.h"
#include <stdio.h> #endif
#if !HAVE_FGETLN
#include <stdlib.h> #include <stdlib.h>
#ifndef HAVE_NBTOOL_CONFIG_H
/* These headers are required, but included from nbtool_config.h */
#include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#endif
char * char *
fgetln(fp, len) fgetln(FILE *fp, size_t *len)
FILE *fp;
size_t *len;
{ {
static char *buf = NULL; static char *buf = NULL;
static size_t bufsiz = 0; static size_t bufsiz = 0;
...@@ -61,8 +61,8 @@ fgetln(fp, len) ...@@ -61,8 +61,8 @@ fgetln(fp, len)
if (fgets(buf, bufsiz, fp) == NULL) if (fgets(buf, bufsiz, fp) == NULL)
return NULL; return NULL;
*len = 0;
*len = 0;
while ((ptr = strchr(&buf[*len], '\n')) == NULL) { while ((ptr = strchr(&buf[*len], '\n')) == NULL) {
size_t nbufsiz = bufsiz + BUFSIZ; size_t nbufsiz = bufsiz + BUFSIZ;
char *nbuf = realloc(buf, nbufsiz); char *nbuf = realloc(buf, nbufsiz);
...@@ -76,13 +76,33 @@ fgetln(fp, len) ...@@ -76,13 +76,33 @@ fgetln(fp, len)
} else } else
buf = nbuf; buf = nbuf;
*len = bufsiz; if (fgets(&buf[bufsiz], BUFSIZ, fp) == NULL) {
if (fgets(&buf[bufsiz], BUFSIZ, fp) == NULL) buf[bufsiz] = '\0';
*len = strlen(buf);
return buf; return buf;
}
*len = bufsiz;
bufsiz = nbufsiz; bufsiz = nbufsiz;
} }
*len = (ptr - buf) + 1; *len = (ptr - buf) + 1;
return buf; return buf;
} }
#endif
#ifdef TEST
int
main(int argc, char *argv[])
{
char *p;
size_t len;
while ((p = fgetln(stdin, &len)) != NULL) {
(void)printf("%zu %s", len, p);
free(p);
}
return 0;
}
#endif
/* $NetBSD: strlcat.c,v 1.3 2007/06/04 18:19:27 christos Exp $ */
/* $OpenBSD: strlcat.c,v 1.10 2003/04/12 21:56:39 millert Exp $ */
/* /*
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
* All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Permission to use, copy, modify, and distribute this software for any
* modification, are permitted provided that the following conditions * purpose with or without fee is hereby granted, provided that the above
* are met: * copyright notice and this permission notice appear in all copies.
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, * THE SOFTWARE IS PROVIDED "AS IS" AND TODD C. MILLER DISCLAIMS ALL
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL TODD C. MILLER BE LIABLE
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
* 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.
*/ */
#if !defined(_KERNEL) && !defined(_STANDALONE)
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#else
#include "config.h" #include "config.h"
#endif
#if defined(LIBC_SCCS) && !defined(lint) #if defined(LIBC_SCCS) && !defined(lint)
static char *rcsid = "$OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp $";
#endif /* LIBC_SCCS and not lint */ #endif /* LIBC_SCCS and not lint */
#ifndef lint
static const char rcsid[] =
"$FreeBSD: src/lib/libc/string/strlcat.c,v 1.2.4.2 2001/07/09 23:30:06 obrien Exp $";
#endif
#ifdef _LIBC
#include "namespace.h"
#endif
#include <sys/types.h> #include <sys/types.h>
#include <assert.h>
#include <string.h> #include <string.h>
#ifdef _LIBC
# ifdef __weak_alias
__weak_alias(strlcat, _strlcat)
# endif
#endif
#else
#include <lib/libkern/libkern.h>
#endif /* !_KERNEL && !_STANDALONE */
#if !HAVE_STRLCAT
/* /*
* Appends src to string dst of size siz (unlike strncat, siz is the * Appends src to string dst of size siz (unlike strncat, siz is the
* full size of dst, not space left). At most siz-1 characters * full size of dst, not space left). At most siz-1 characters
* will be copied. Always NUL terminates (unless siz <= strlen(dst)). * will be copied. Always NUL terminates (unless siz <= strlen(dst)).
* Returns strlen(initial dst) + strlen(src); if retval >= siz, * Returns strlen(src) + MIN(siz, strlen(initial dst)).
* truncation occurred. * If retval >= siz, truncation occurred.
*/ */
size_t strlcat(dst, src, siz) size_t
char *dst; strlcat(char *dst, const char *src, size_t siz)
const char *src;
size_t siz;
{ {
register char *d = dst; char *d = dst;
register const char *s = src; const char *s = src;
register size_t n = siz; size_t n = siz;
size_t dlen; size_t dlen;
_DIAGASSERT(dst != NULL);
_DIAGASSERT(src != NULL);
/* Find the end of dst and adjust bytes left but don't go past end */ /* Find the end of dst and adjust bytes left but don't go past end */
while (n-- != 0 && *d != '\0') while (n-- != 0 && *d != '\0')
d++; d++;
...@@ -73,3 +82,4 @@ size_t strlcat(dst, src, siz) ...@@ -73,3 +82,4 @@ size_t strlcat(dst, src, siz)
return(dlen + (s - src)); /* count does not include NUL */ return(dlen + (s - src)); /* count does not include NUL */
} }
#endif
/* $OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp $ */ /* $NetBSD: strlcpy.c,v 1.3 2007/06/04 18:19:27 christos Exp $ */
/* $OpenBSD: strlcpy.c,v 1.7 2003/04/12 21:56:39 millert Exp $ */
/* /*
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
* All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Permission to use, copy, modify, and distribute this software for any
* modification, are permitted provided that the following conditions * purpose with or without fee is hereby granted, provided that the above
* are met: * copyright notice and this permission notice appear in all copies.
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, * THE SOFTWARE IS PROVIDED "AS IS" AND TODD C. MILLER DISCLAIMS ALL
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL TODD C. MILLER BE LIABLE
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
* 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.
*/ */
#if !defined(_KERNEL) && !defined(_STANDALONE)
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#else
#include "config.h" #include "config.h"
#if defined(LIBC_SCCS) && !defined(lint)
#if 0
static char *rcsid = "$OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp $";
#endif #endif
#if defined(LIBC_SCCS) && !defined(lint)
#endif /* LIBC_SCCS and not lint */ #endif /* LIBC_SCCS and not lint */
#ifndef lint
static const char rcsid[] =
"$FreeBSD: src/lib/libc/string/strlcpy.c,v 1.2.4.1 2001/07/09 23:30:06 obrien Exp $";
#endif
#ifdef _LIBC
#include "namespace.h"
#endif
#include <sys/types.h> #include <sys/types.h>
#include <assert.h>
#include <string.h> #include <string.h>
#ifdef _LIBC
# ifdef __weak_alias
__weak_alias(strlcpy, _strlcpy)
# endif
#endif
#else
#include <lib/libkern/libkern.h>
#endif /* !_KERNEL && !_STANDALONE */
#if !HAVE_STRLCPY
/* /*
* Copy src to string dst of size siz. At most siz-1 characters * Copy src to string dst of size siz. At most siz-1 characters
* will be copied. Always NUL terminates (unless siz == 0). * will be copied. Always NUL terminates (unless siz == 0).
* Returns strlen(src); if retval >= siz, truncation occurred. * Returns strlen(src); if retval >= siz, truncation occurred.
*/ */
size_t strlcpy(dst, src, siz) size_t
char *dst; strlcpy(char *dst, const char *src, size_t siz)
const char *src;
size_t siz;
{ {
register char *d = dst; char *d = dst;
register const char *s = src; const char *s = src;
register size_t n = siz; size_t n = siz;
_DIAGASSERT(dst != NULL);
_DIAGASSERT(src != NULL);
/* Copy as many bytes as will fit */ /* Copy as many bytes as will fit */
if (n != 0 && --n != 0) { if (n != 0 && --n != 0) {
...@@ -73,3 +77,4 @@ size_t strlcpy(dst, src, siz) ...@@ -73,3 +77,4 @@ size_t strlcpy(dst, src, siz)
return(s - src - 1); /* count does not include NUL */ return(s - src - 1); /* count does not include NUL */
} }
#endif
/* $NetBSD: unvis.c,v 1.22 2002/03/23 17:38:27 christos Exp $ */ /* $NetBSD: unvis.c,v 1.28 2005/09/13 01:44:09 christos Exp $ */
/*- /*-
* Copyright (c) 1989, 1993 * Copyright (c) 1989, 1993
...@@ -12,11 +12,7 @@ ...@@ -12,11 +12,7 @@
* 2. Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software * 3. Neither the name of the University nor the names of its contributors
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software * may be used to endorse or promote products derived from this software
* without specific prior written permission. * without specific prior written permission.
* *
...@@ -34,34 +30,30 @@ ...@@ -34,34 +30,30 @@
*/ */
#include "config.h" #include "config.h"
#if defined(LIBC_SCCS) && !defined(lint) #if defined(LIBC_SCCS) && !defined(lint)
#if 0 #if 0
static char sccsid[] = "@(#)unvis.c 8.1 (Berkeley) 6/4/93"; static char sccsid[] = "@(#)unvis.c 8.1 (Berkeley) 6/4/93";
#else #else
__RCSID("$NetBSD: unvis.c,v 1.22 2002/03/23 17:38:27 christos Exp $");
#endif #endif
#endif /* LIBC_SCCS and not lint */ #endif /* LIBC_SCCS and not lint */
#define __LIBC12_SOURCE__
#include <sys/types.h> #include <sys/types.h>
#include <assert.h> #include <assert.h>
#include <ctype.h> #include <ctype.h>
#include <stdio.h> #include <stdio.h>
#ifdef HAVE_VIS_H
#include <vis.h>
#else
#include "np/vis.h" #include "np/vis.h"
#endif
#ifdef __weak_alias #ifdef __weak_alias
__weak_alias(strunvis,_strunvis) __weak_alias(strunvis,_strunvis)
__weak_alias(unvis,_unvis)
#endif #endif
#ifdef __warn_references #if !HAVE_VIS
__warn_references(unvis,
"warning: reference to compatibility unvis(); include <vis.h> for correct reference")
#endif
#if !HAVE_VIS_H
/* /*
* decode driven by state machine * decode driven by state machine
*/ */
...@@ -72,30 +64,22 @@ __warn_references(unvis, ...@@ -72,30 +64,22 @@ __warn_references(unvis,
#define S_CTRL 4 /* control char started (^) */ #define S_CTRL 4 /* control char started (^) */
#define S_OCTAL2 5 /* octal digit 2 */ #define S_OCTAL2 5 /* octal digit 2 */
#define S_OCTAL3 6 /* octal digit 3 */ #define S_OCTAL3 6 /* octal digit 3 */
#define S_HEX1 7 /* hex digit */ #define S_HEX1 7 /* hex digit */
#define S_HEX2 8 /* hex digit 2 */ #define S_HEX2 8 /* hex digit 2 */
#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7') #define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7')
#define xtod(c) (isdigit(c) ? (c - '0') : ((tolower(c) - 'a') + 10)) #define xtod(c) (isdigit(c) ? (c - '0') : ((tolower(c) - 'a') + 10))
int
unvis(cp, c, astate, flag)
char *cp;
int c;
int *astate, flag;
{
return __unvis13(cp, (int)c, astate, flag);
}
/* /*
* unvis - decode characters previously encoded by vis * unvis - decode characters previously encoded by vis
*/ */
int int
__unvis13(cp, c, astate, flag) unvis(cp, c, astate, flag)
char *cp; char *cp;
int c; int c;
int *astate, flag; int *astate, flag;
{ {
unsigned char uc = (unsigned char)c;
_DIAGASSERT(cp != NULL); _DIAGASSERT(cp != NULL);
_DIAGASSERT(astate != NULL); _DIAGASSERT(astate != NULL);
...@@ -105,7 +89,7 @@ __unvis13(cp, c, astate, flag) ...@@ -105,7 +89,7 @@ __unvis13(cp, c, astate, flag)
|| *astate == S_HEX2) { || *astate == S_HEX2) {
*astate = S_GROUND; *astate = S_GROUND;
return (UNVIS_VALID); return (UNVIS_VALID);
} }
return (*astate == S_GROUND ? UNVIS_NOCHAR : UNVIS_SYNBAD); return (*astate == S_GROUND ? UNVIS_NOCHAR : UNVIS_SYNBAD);
} }
...@@ -116,7 +100,7 @@ __unvis13(cp, c, astate, flag) ...@@ -116,7 +100,7 @@ __unvis13(cp, c, astate, flag)
if (c == '\\') { if (c == '\\') {
*astate = S_START; *astate = S_START;
return (0); return (0);
} }
if ((flag & VIS_HTTPSTYLE) && c == '%') { if ((flag & VIS_HTTPSTYLE) && c == '%') {
*astate = S_HEX1; *astate = S_HEX1;
return (0); return (0);
...@@ -193,7 +177,7 @@ __unvis13(cp, c, astate, flag) ...@@ -193,7 +177,7 @@ __unvis13(cp, c, astate, flag)
} }
*astate = S_GROUND; *astate = S_GROUND;
return (UNVIS_SYNBAD); return (UNVIS_SYNBAD);
case S_META: case S_META:
if (c == '-') if (c == '-')
*astate = S_META1; *astate = S_META1;
...@@ -204,12 +188,12 @@ __unvis13(cp, c, astate, flag) ...@@ -204,12 +188,12 @@ __unvis13(cp, c, astate, flag)
return (UNVIS_SYNBAD); return (UNVIS_SYNBAD);
} }
return (0); return (0);
case S_META1: case S_META1:
*astate = S_GROUND; *astate = S_GROUND;
*cp |= c; *cp |= c;
return (UNVIS_VALID); return (UNVIS_VALID);
case S_CTRL: case S_CTRL:
if (c == '?') if (c == '?')
*cp |= 0177; *cp |= 0177;
...@@ -219,23 +203,23 @@ __unvis13(cp, c, astate, flag) ...@@ -219,23 +203,23 @@ __unvis13(cp, c, astate, flag)
return (UNVIS_VALID); return (UNVIS_VALID);
case S_OCTAL2: /* second possible octal digit */ case S_OCTAL2: /* second possible octal digit */
if (isoctal(c)) { if (isoctal(uc)) {
/* /*
* yes - and maybe a third * yes - and maybe a third
*/ */
*cp = (*cp << 3) + (c - '0'); *cp = (*cp << 3) + (c - '0');
*astate = S_OCTAL3; *astate = S_OCTAL3;
return (0); return (0);
} }
/* /*
* no - done with current sequence, push back passed char * no - done with current sequence, push back passed char
*/ */
*astate = S_GROUND; *astate = S_GROUND;
return (UNVIS_VALIDPUSH); return (UNVIS_VALIDPUSH);
case S_OCTAL3: /* third possible octal digit */ case S_OCTAL3: /* third possible octal digit */
*astate = S_GROUND; *astate = S_GROUND;
if (isoctal(c)) { if (isoctal(uc)) {
*cp = (*cp << 3) + (c - '0'); *cp = (*cp << 3) + (c - '0');
return (UNVIS_VALID); return (UNVIS_VALID);
} }
...@@ -243,27 +227,30 @@ __unvis13(cp, c, astate, flag) ...@@ -243,27 +227,30 @@ __unvis13(cp, c, astate, flag)
* we were done, push back passed char * we were done, push back passed char
*/ */
return (UNVIS_VALIDPUSH); return (UNVIS_VALIDPUSH);
case S_HEX1: case S_HEX1:
if (isxdigit(c)) { if (isxdigit(uc)) {
*cp = xtod(c); *cp = xtod(uc);
*astate = S_HEX2; *astate = S_HEX2;
return (0); return (0);
} }
/* /*
* no - done with current sequence, push back passed char * no - done with current sequence, push back passed char
*/ */
*astate = S_GROUND; *astate = S_GROUND;
return (UNVIS_VALIDPUSH); return (UNVIS_VALIDPUSH);
case S_HEX2: case S_HEX2:
*astate = S_GROUND; *astate = S_GROUND;
if (isxdigit(c)) { if (isxdigit(uc)) {
*cp = xtod(c) | (*cp << 4); *cp = xtod(uc) | (*cp << 4);
return (UNVIS_VALID); return (UNVIS_VALID);
} }
return (UNVIS_VALIDPUSH); return (UNVIS_VALIDPUSH);
default:
/* default:
* decoder in unknown state - (probably uninitialized) /*
* decoder in unknown state - (probably uninitialized)
*/ */
*astate = S_GROUND; *astate = S_GROUND;
return (UNVIS_SYNBAD); return (UNVIS_SYNBAD);
...@@ -271,7 +258,7 @@ __unvis13(cp, c, astate, flag) ...@@ -271,7 +258,7 @@ __unvis13(cp, c, astate, flag)
} }
/* /*
* strunvis - decode src into dst * strunvis - decode src into dst
* *
* Number of chars decoded into dst is returned, -1 on error. * Number of chars decoded into dst is returned, -1 on error.
* Dst is null terminated. * Dst is null terminated.
...@@ -291,8 +278,8 @@ strunvisx(dst, src, flag) ...@@ -291,8 +278,8 @@ strunvisx(dst, src, flag)
_DIAGASSERT(dst != NULL); _DIAGASSERT(dst != NULL);
while ((c = *src++) != '\0') { while ((c = *src++) != '\0') {
again: again:
switch (__unvis13(dst, c, &state, flag)) { switch (unvis(dst, c, &state, flag)) {
case UNVIS_VALID: case UNVIS_VALID:
dst++; dst++;
break; break;
...@@ -306,7 +293,7 @@ strunvisx(dst, src, flag) ...@@ -306,7 +293,7 @@ strunvisx(dst, src, flag)
return (-1); return (-1);
} }
} }
if (__unvis13(dst, c, &state, UNVIS_END) == UNVIS_VALID) if (unvis(dst, c, &state, UNVIS_END) == UNVIS_VALID)
dst++; dst++;
*dst = '\0'; *dst = '\0';
return (dst - start); return (dst - start);
......
This diff is collapsed.
/* $NetBSD: vis.h,v 1.12 2002/03/23 17:39:05 christos Exp $ */ /* $NetBSD: vis.h,v 1.16 2005/09/13 01:44:32 christos Exp $ */
/*- /*-
* Copyright (c) 1990, 1993 * Copyright (c) 1990, 1993
...@@ -12,11 +12,7 @@ ...@@ -12,11 +12,7 @@
* 2. Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software * 3. Neither the name of the University nor the names of its contributors
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software * may be used to endorse or promote products derived from this software
* without specific prior written permission. * without specific prior written permission.
* *
...@@ -38,9 +34,7 @@ ...@@ -38,9 +34,7 @@
#ifndef _VIS_H_ #ifndef _VIS_H_
#define _VIS_H_ #define _VIS_H_
#ifdef HAVE_SYS_CDEFS_H #include <sys/types.h>
#include <sys/cdefs.h>
#endif
/* /*
* to select alternate encoding format * to select alternate encoding format
...@@ -78,6 +72,7 @@ ...@@ -78,6 +72,7 @@
*/ */
#define UNVIS_END 1 /* no more characters */ #define UNVIS_END 1 /* no more characters */
__BEGIN_DECLS
char *vis(char *, int, int, int); char *vis(char *, int, int, int);
char *svis(char *, int, int, int, const char *); char *svis(char *, int, int, int, const char *);
int strvis(char *, const char *, int); int strvis(char *, const char *, int);
...@@ -86,11 +81,7 @@ int strvisx(char *, const char *, size_t, int); ...@@ -86,11 +81,7 @@ int strvisx(char *, 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 strunvis(char *, const char *); int strunvis(char *, const char *);
int strunvisx(char *, const char *, int); int strunvisx(char *, const char *, int);
#ifdef __LIBC12_SOURCE__
int unvis(char *, int, int *, int); int unvis(char *, int, int *, int);
int __unvis13(char *, int, int *, int); __END_DECLS
#else
int unvis(char *, int, int *, int) __RENAME(__unvis13);
#endif
#endif /* !_VIS_H_ */ #endif /* !_VIS_H_ */
/* $NetBSD: parse.c,v 1.20 2003/12/05 13:37:48 lukem Exp $ */ /* $NetBSD: parse.c,v 1.22 2005/05/29 04:58:15 lukem Exp $ */
/*- /*-
* Copyright (c) 1992, 1993 * Copyright (c) 1992, 1993
...@@ -32,7 +32,13 @@ ...@@ -32,7 +32,13 @@
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
#include <config.h> #include "config.h"
#if !defined(lint) && !defined(SCCSID)
#if 0
static char sccsid[] = "@(#)parse.c 8.1 (Berkeley) 6/4/93";
#else
#endif
#endif /* not lint && not SCCSID */
/* /*
* parse.c: parse an editline extended command * parse.c: parse an editline extended command
...@@ -129,7 +135,7 @@ el_parse(EditLine *el, int argc, const char *argv[]) ...@@ -129,7 +135,7 @@ el_parse(EditLine *el, int argc, const char *argv[])
* the appropriate character or -1 if the escape is not valid * the appropriate character or -1 if the escape is not valid
*/ */
protected int protected int
parse__escape(const char **const ptr) parse__escape(const char **ptr)
{ {
const char *p; const char *p;
int c; int c;
......
/* $NetBSD: parse.h,v 1.5 2003/08/07 16:44:32 agc Exp $ */ /* $NetBSD: parse.h,v 1.6 2005/05/29 04:58:15 lukem Exp $ */
/*- /*-
* Copyright (c) 1992, 1993 * Copyright (c) 1992, 1993
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
#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 ** const); 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 *);
......
...@@ -32,7 +32,13 @@ ...@@ -32,7 +32,13 @@
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
#include <config.h> #include "config.h"
#if !defined(lint) && !defined(SCCSID)
#if 0
static char sccsid[] = "@(#)prompt.c 8.1 (Berkeley) 6/4/93";
#else
#endif
#endif /* not lint && not SCCSID */
/* /*
* prompt.c: Prompt printing functions * prompt.c: Prompt printing functions
......
This diff is collapsed.
/* $NetBSD: read.h,v 1.4 2004/02/27 14:52:18 christos Exp $ */ /* $NetBSD: read.h,v 1.6 2008/04/29 06:53:01 martin Exp $ */
/*- /*-
* Copyright (c) 2001 The NetBSD Foundation, Inc. * Copyright (c) 2001 The NetBSD Foundation, Inc.
...@@ -15,13 +15,6 @@ ...@@ -15,13 +15,6 @@
* 2. Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * 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 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/* $NetBSD: sig.h,v 1.5 2003/08/07 16:44:33 agc Exp $ */ /* $NetBSD: sig.h,v 1.6 2008/07/12 15:27:14 christos Exp $ */
/*- /*-
* Copyright (c) 1992, 1993 * Copyright (c) 1992, 1993
...@@ -51,7 +51,6 @@ ...@@ -51,7 +51,6 @@
#define ALLSIGS \ #define ALLSIGS \
_DO(SIGINT) \ _DO(SIGINT) \
_DO(SIGTSTP) \ _DO(SIGTSTP) \
_DO(SIGSTOP) \
_DO(SIGQUIT) \ _DO(SIGQUIT) \
_DO(SIGHUP) \ _DO(SIGHUP) \
_DO(SIGTERM) \ _DO(SIGTERM) \
......
This diff is collapsed.
size_t strlcpy(char *dst, const char *src, size_t size);
size_t strlcat(char *dst, const char *src, size_t size);
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