Merged Performance Version 0.2.1 with latest 5.1 tree (last push 11 feb 14.01.13 2009)

This commit is contained in:
Mikael Ronstrom 2009-02-17 13:24:09 +01:00
commit dd9119be20
1739 changed files with 40835 additions and 25223 deletions

View file

@ -1289,6 +1289,7 @@ mysql-test/funcs_1.log
mysql-test/funcs_1.tar
mysql-test/gmon.out
mysql-test/install_test_db
mysql-test/lib/My/SafeProcess/my_safe_process
mysql-test/lib/init_db.sql
mysql-test/linux_sys_vars.inc
mysql-test/load_sysvars.inc
@ -2097,10 +2098,13 @@ sql/.libs/udf_example.lai
sql/.libs/udf_example.so.0
sql/.libs/udf_example.so.0.0.0
sql/client.c
sql/Doxyfile
sql/f.c
sql/gen_lex_hash
sql/gmon.out
sql/handlerton.cc
sql/html
sql/latex
sql/lex_hash.h
sql/link_sources
sql/max/*

View file

@ -11,16 +11,33 @@ test -f Makefile && make maintainer-clean
path=`dirname $0`
. $path/autorun.sh
gmake=
for x in gmake gnumake make; do
if $x --version 2>/dev/null | grep GNU > /dev/null; then
gmake=$x
break;
fi
done
if [ -z "$gmake" ]; then
# Our build may not depend on GNU make, but I wouldn't count on it
echo "Please install GNU make, and ensure it is in your path as gnumake, gmake, or make" >&2
exit 2
fi
# Default to gcc for CC and CXX
if test -z "$CXX" ; then
export CXX
CXX=gcc
# Set some required compile options
if test -z "$CXXFLAGS" ; then
export CXXFLAGS
CXXFLAGS="-felide-constructors -fno-exceptions -fno-rtti"
fi
fi
if test -z "$CC" ; then
export CC
CC=gcc
fi
@ -28,36 +45,22 @@ fi
# Use ccache, if available
if ccache -V > /dev/null 2>&1
then
if echo "$CC" | grep "ccache" > /dev/null
if echo "$CC" | grep -v ccache > /dev/null
then
:
else
export CC
CC="ccache $CC"
fi
if echo "$CXX" | grep "ccache" > /dev/null
if echo "$CXX" | grep -v ccache > /dev/null
then
:
else
export CXX
CXX="ccache $CXX"
fi
fi
if test -z "$MAKE"
then
if gmake -v > /dev/null 2>&1
then
MAKE="gmake"
else
MAKE="make"
fi
fi
export CC CXX MAKE
# Make sure to enable all features that affect "make dist"
# Remember that configure restricts the man pages to the configured features !
./configure \
--with-embedded-server \
--with-ndbcluster
$MAKE
$gmake

View file

@ -98,6 +98,10 @@ IF(CYBOZU)
ADD_DEFINITIONS(-DCYBOZU)
ENDIF(CYBOZU)
IF(EXTRA_DEBUG)
ADD_DEFINITIONS(-D EXTRA_DEBUG)
ENDIF(EXTRA_DEBUG)
# in some places we use DBUG_OFF
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DDBUG_OFF")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -DDBUG_OFF")
@ -254,3 +258,4 @@ IF(WITH_EMBEDDED_SERVER)
ADD_SUBDIRECTORY(libmysqld)
ADD_SUBDIRECTORY(libmysqld/examples)
ENDIF(WITH_EMBEDDED_SERVER)
ADD_SUBDIRECTORY(mysql-test/lib/My/SafeProcess)

View file

@ -1,4 +1,4 @@
# Copyright (C) 2000-2006 MySQL AB
# Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -121,6 +121,10 @@ test-reprepare:
test: test-unit test-ns test-pr
smoke:
cd mysql-test ; \
@PERL@ ./mysql-test-run.pl --do-test=s
test-full: test test-nr test-ps
test-force:
@ -159,6 +163,8 @@ test-bt:
@PERL@ ./mysql-test-run.pl --force --comment=partitions --suite=parts
-cd mysql-test ; MTR_BUILD_THREAD=auto \
@PERL@ ./mysql-test-run.pl --force --comment=stress --suite=stress
-cd mysql-test ; MTR_BUILD_THREAD=auto \
@PERL@ ./mysql-test-run.pl --force --comment=jp --suite=jp
-if [ -d mysql-test/suite/nist ] ; then \
cd mysql-test ; MTR_BUILD_THREAD=auto \
@PERL@ ./mysql-test-run.pl --comment=nist --force --suite=nist ; \
@ -175,15 +181,28 @@ test-bt:
echo "no program found for 'embedded' tests - skipped testing" ; \
fi
# Re-enable the "jp" suite when bug#28563 is fixed
# -cd mysql-test ; MTR_BUILD_THREAD=auto \
# @PERL@ ./mysql-test-run.pl --force --comment=jp --suite=jp
test-bt-fast:
-cd mysql-test ; MTR_BUILD_THREAD=auto \
@PERL@ ./mysql-test-run.pl --comment=ps --force --timer \
--skip-ndbcluster --ps-protocol --report-features
-if [ -e bin/ndbd -o -e storage/ndb/src/kernel/ndbd ] ; then \
cd mysql-test ; \
MTR_BUILD_THREAD=auto \
@PERL@ ./mysql-test-run.pl --comment=ndb --force --timer \
--with-ndbcluster-only ; \
else \
echo "no program found for 'ndbcluster' tests - skipped testing" ; \
fi
-cd mysql-test ; MTR_BUILD_THREAD=auto \
@PERL@ ./mysql-test-run.pl --force --comment=stress --suite=stress
test-bt-debug:
-cd mysql-test ; MTR_BUILD_THREAD=auto \
@PERL@ ./mysql-test-run.pl --comment=debug --force --timer \
--skip-ndbcluster --skip-rpl --report-features
test-bt-debug-fast:
# Keep these for a while
test-pl: test
test-full-pl: test-full

View file

@ -32,8 +32,8 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include
ADD_EXECUTABLE(mysql completion_hash.cc mysql.cc readline.cc sql_string.cc ../mysys/my_conio.c)
TARGET_LINK_LIBRARIES(mysql mysqlclient_notls wsock32)
ADD_EXECUTABLE(mysqltest mysqltest.c)
SET_SOURCE_FILES_PROPERTIES(mysqltest.c PROPERTIES COMPILE_FLAGS "-DTHREADS")
ADD_EXECUTABLE(mysqltest mysqltest.cc)
SET_SOURCE_FILES_PROPERTIES(mysqltest.cc PROPERTIES COMPILE_FLAGS "-DTHREADS")
TARGET_LINK_LIBRARIES(mysqltest mysqlclient mysys regex wsock32 dbug)
ADD_EXECUTABLE(mysqlcheck mysqlcheck.c)

View file

@ -86,9 +86,9 @@ mysqlslap_LDADD = $(CXXLDFLAGS) $(CLIENT_THREAD_LIBS) \
$(LIBMYSQLCLIENT_LA) \
$(top_builddir)/mysys/libmysys.a
mysqltest_SOURCES= mysqltest.c
mysqltest_CFLAGS= -DTHREAD -UUNDEF_THREADS_HACK
mysqltest_LDADD = $(CXXLDFLAGS) \
mysqltest_SOURCES= mysqltest.cc
mysqltest_CXXFLAGS= -DTHREAD -UUNDEF_THREADS_HACK
mysqltest_LDADD = $(CXXLDFLAGS) $(CLIENT_THREAD_LIBS) \
@CLIENT_EXTRA_LDFLAGS@ \
$(LIBMYSQLCLIENT_LA) \
$(top_builddir)/mysys/libmysys.a \

View file

@ -1535,7 +1535,7 @@ static void usage(int version)
if (version)
return;
printf("\
Copyright (C) 2000-2008 MySQL AB\n\
Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.\n\
This software comes with ABSOLUTELY NO WARRANTY. This is free software,\n\
and you are welcome to modify and redistribute it under the GPL license\n");
printf("Usage: %s [OPTIONS] [database]\n", my_progname);
@ -2020,7 +2020,7 @@ static bool add_line(String &buffer,char *line,char *in_string,
{
if (!preserve_comments)
{
// Skip spaces at the beggining of a statement
// Skip spaces at the beginning of a statement
if (my_isspace(charset_info,inchar) && (out == line) &&
buffer.is_empty())
continue;
@ -2044,7 +2044,8 @@ static bool add_line(String &buffer,char *line,char *in_string,
}
#endif
if (!*ml_comment && inchar == '\\' &&
!(mysql.server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES))
!(*in_string &&
(mysql.server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)))
{
// Found possbile one character command like \c
@ -2103,37 +2104,6 @@ static bool add_line(String &buffer,char *line,char *in_string,
continue;
}
}
else if (!*ml_comment && !*in_string &&
(end_of_line - pos) >= 10 &&
!my_strnncoll(charset_info, (uchar*) pos, 10,
(const uchar*) "delimiter ", 10))
{
// Flush previously accepted characters
if (out != line)
{
buffer.append(line, (uint32) (out - line));
out= line;
}
// Flush possible comments in the buffer
if (!buffer.is_empty())
{
if (com_go(&buffer, 0) > 0) // < 0 is not fatal
DBUG_RETURN(1);
buffer.length(0);
}
/*
Delimiter wants the get rest of the given line as argument to
allow one to change ';' to ';;' and back
*/
buffer.append(pos);
if (com_delimiter(&buffer, pos) > 0)
DBUG_RETURN(1);
buffer.length(0);
break;
}
else if (!*ml_comment && !*in_string && is_prefix(pos, delimiter))
{
// Found a statement. Continue parsing after the delimiter
@ -2196,8 +2166,24 @@ static bool add_line(String &buffer,char *line,char *in_string,
// comment to end of line
if (preserve_comments)
{
bool started_with_nothing= !buffer.length();
buffer.append(pos);
/*
A single-line comment by itself gets sent immediately so that
client commands (delimiter, status, etc) will be interpreted on
the next line.
*/
if (started_with_nothing)
{
if (com_go(&buffer, 0) > 0) // < 0 is not fatal
DBUG_RETURN(1);
buffer.length(0);
}
}
break;
}
else if (!*in_string && inchar == '/' && *(pos+1) == '*' &&
@ -2284,8 +2270,10 @@ extern "C" char **new_mysql_completion (const char *text, int start, int end);
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)
#elif defined(USE_LIBEDIT_INTERFACE)
extern "C" int no_completion(const char*,int)
#else
extern "C" char *no_completion()
#endif

View file

@ -620,6 +620,20 @@ static int run_mysqlcheck_upgrade(void)
}
static int run_mysqlcheck_fixnames(void)
{
verbose("Running 'mysqlcheck'...");
return run_tool(mysqlcheck_path,
NULL, /* Send output from mysqlcheck directly to screen */
"--no-defaults",
ds_args.str,
"--all-databases",
"--fix-db-names",
"--fix-table-names",
NULL);
}
static const char *expected_errors[]=
{
"ERROR 1060", /* Duplicate column name */
@ -782,7 +796,8 @@ int main(int argc, char **argv)
/*
Run "mysqlcheck" and "mysql_fix_privilege_tables.sql"
*/
if (run_mysqlcheck_upgrade() ||
if (run_mysqlcheck_fixnames() ||
run_mysqlcheck_upgrade() ||
run_sql_fix_privilege_tables())
{
/*

View file

@ -23,10 +23,6 @@
#include <sys/stat.h>
#include <mysql.h>
#ifdef LATER_HAVE_NDBCLUSTER_DB
#include "../ndb/src/mgmclient/ndb_mgmclient.h"
#endif
#define ADMIN_VERSION "8.42"
#define MAX_MYSQL_VAR 256
#define SHUTDOWN_DEF_TIMEOUT 3600 /* Wait for shutdown */
@ -46,10 +42,6 @@ static uint tcp_port = 0, option_wait = 0, option_silent=0, nr_iterations;
static uint opt_count_iterations= 0, my_end_arg;
static ulong opt_connect_timeout, opt_shutdown_timeout;
static char * unix_port=0;
#ifdef LATER_HAVE_NDBCLUSTER_DB
static my_bool opt_ndbcluster=0;
static char *opt_ndb_connectstring=0;
#endif
#ifdef HAVE_SMEM
static char *shared_memory_base_name=0;
@ -105,9 +97,6 @@ enum commands {
ADMIN_PING, ADMIN_EXTENDED_STATUS, ADMIN_FLUSH_STATUS,
ADMIN_FLUSH_PRIVILEGES, ADMIN_START_SLAVE, ADMIN_STOP_SLAVE,
ADMIN_FLUSH_THREADS, ADMIN_OLD_PASSWORD
#ifdef LATER_HAVE_NDBCLUSTER_DB
,ADMIN_NDB_MGM
#endif
};
static const char *command_names[]= {
"create", "drop", "shutdown",
@ -118,9 +107,6 @@ static const char *command_names[]= {
"ping", "extended-status", "flush-status",
"flush-privileges", "start-slave", "stop-slave",
"flush-threads","old-password",
#ifdef LATER_HAVE_NDBCLUSTER_DB
"ndb-mgm",
#endif
NullS
};
@ -224,14 +210,6 @@ static struct my_option my_long_options[] =
{"shutdown_timeout", OPT_SHUTDOWN_TIMEOUT, "", (uchar**) &opt_shutdown_timeout,
(uchar**) &opt_shutdown_timeout, 0, GET_ULONG, REQUIRED_ARG,
SHUTDOWN_DEF_TIMEOUT, 0, 3600*12, 0, 1, 0},
#ifdef LATER_HAVE_NDBCLUSTER_DB
{"ndbcluster", OPT_NDBCLUSTER, ""
"", (uchar**) &opt_ndbcluster,
(uchar**) &opt_ndbcluster, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"ndb-connectstring", OPT_NDB_CONNECTSTRING, ""
"", (uchar**) &opt_ndb_connectstring,
(uchar**) &opt_ndb_connectstring, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
#endif
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};
@ -634,7 +612,7 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv)
case ADMIN_VER:
new_line=1;
print_version();
puts("Copyright (C) 2000-2006 MySQL AB");
puts("Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.");
puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n");
printf("Server version\t\t%s\n", mysql_get_server_info(mysql));
printf("Protocol version\t%d\n", mysql_get_proto_info(mysql));
@ -984,24 +962,6 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv)
}
mysql->reconnect=1; /* Automatic reconnect is default */
break;
#ifdef LATER_HAVE_NDBCLUSTER_DB
case ADMIN_NDB_MGM:
{
if (argc < 2)
{
my_printf_error(0, "Too few arguments to ndb-mgm", error_flags);
return 1;
}
{
Ndb_mgmclient_handle cmd=
ndb_mgmclient_handle_create(opt_ndb_connectstring);
ndb_mgmclient_execute(cmd, --argc, ++argv);
ndb_mgmclient_handle_destroy(cmd);
}
argc= 0;
}
break;
#endif
default:
my_printf_error(0, "Unknown command: '%-.60s'", error_flags, argv[0]);
return 1;
@ -1023,7 +983,7 @@ static void print_version(void)
static void usage(void)
{
print_version();
puts("Copyright (C) 2000-2006 MySQL AB");
puts("Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.");
puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n");
puts("Administration program for the mysqld daemon.");
printf("Usage: %s [OPTIONS] command command....\n", my_progname);

View file

@ -40,15 +40,13 @@ static uint verbose = 0, opt_mysql_port=0;
static int my_end_arg;
static char * opt_mysql_unix_port = 0;
static char *opt_password = 0, *current_user = 0,
*default_charset = (char *)MYSQL_DEFAULT_CHARSET_NAME,
*current_host = 0;
*default_charset= 0, *current_host= 0;
static int first_error = 0;
DYNAMIC_ARRAY tables4repair;
#ifdef HAVE_SMEM
static char *shared_memory_base_name=0;
#endif
static uint opt_protocol=0;
static CHARSET_INFO *charset_info= &my_charset_latin1;
enum operations { DO_CHECK, DO_REPAIR, DO_ANALYZE, DO_OPTIMIZE, DO_UPGRADE };
@ -282,12 +280,10 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
break;
case OPT_FIX_DB_NAMES:
what_to_do= DO_UPGRADE;
default_charset= (char*) "utf8";
opt_databases= 1;
break;
case OPT_FIX_TABLE_NAMES:
what_to_do= DO_UPGRADE;
default_charset= (char*) "utf8";
break;
case 'p':
if (argument)
@ -367,11 +363,20 @@ static int get_options(int *argc, char ***argv)
what_to_do = DO_CHECK;
}
/* TODO: This variable is not yet used */
if (strcmp(default_charset, charset_info->csname) &&
!(charset_info= get_charset_by_csname(default_charset,
MY_CS_PRIMARY, MYF(MY_WME))))
exit(1);
/*
If there's no --default-character-set option given with
--fix-table-name or --fix-db-name set the default character set to "utf8".
*/
if (!default_charset && (opt_fix_db_names || opt_fix_table_names))
{
default_charset= (char*) "utf8";
}
if (default_charset && !get_charset_by_csname(default_charset, MY_CS_PRIMARY,
MYF(MY_WME)))
{
printf("Unsupported character set: %s\n", default_charset);
return 1;
}
if (*argc > 0 && opt_alldbs)
{
printf("You should give only options, no arguments at all, with option\n");
@ -779,6 +784,8 @@ static int dbConnect(char *host, char *user, char *passwd)
if (shared_memory_base_name)
mysql_options(&mysql_connection,MYSQL_SHARED_MEMORY_BASE_NAME,shared_memory_base_name);
#endif
if (default_charset)
mysql_options(&mysql_connection, MYSQL_SET_CHARSET_NAME, default_charset);
if (!(sock = mysql_real_connect(&mysql_connection, host, user, passwd,
NULL, opt_mysql_port, opt_mysql_unix_port, 0)))
{

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2000 MySQL AB
/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View file

@ -193,7 +193,7 @@ static void print_version(void)
static void usage(void)
{
print_version();
puts("Copyright (C) 2000-2006 MySQL AB");
puts("Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.");
puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n");
printf("\
Loads tables from text files in various formats. The base name of the\n\

View file

@ -249,7 +249,7 @@ static void print_version(void)
static void usage(void)
{
print_version();
puts("Copyright (C) 2000-2006 MySQL AB");
puts("Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.");
puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n");
puts("Shows the structure of a mysql database (databases,tables and columns)\n");
printf("Usage: %s [OPTIONS] [database [table [column]]]\n",my_progname);

View file

@ -688,9 +688,7 @@ static void usage(void)
{
print_version();
puts("Copyright (C) 2005 MySQL AB");
puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\
\nand you are welcome to modify and redistribute it under the GPL \
license\n");
puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n");
puts("Run a query multiple times against the server\n");
printf("Usage: %s [OPTIONS]\n",my_progname);
print_defaults("my",load_default_groups);

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,4 @@
## 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
AHDR = vi.h emacs.h common.h
@ -12,33 +10,23 @@ noinst_LIBRARIES = libedit.a
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 \
hist.c key.c parse.c read.c refresh.c sig.c term.c \
tty.c help.c fcns.c
EXTRA_libedit_a_SOURCES = np/unvis.c np/strlcpy.c np/vis.c np/strlcat.c \
np/fgetln.c
tty.c help.c fcns.c filecomplete.c \
np/unvis.c np/strlcpy.c np/vis.c np/strlcat.c \
np/fgetln.c
libedit_a_LIBADD = @LIBEDIT_LOBJECTS@
libedit_a_DEPENDENCIES = @LIBEDIT_LOBJECTS@
noinst_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
pkginclude_HEADERS = readline/readline.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
EXTRA_DIST = makelist.sh
CLEANFILES = makelist common.h emacs.h vi.h fcns.h help.h fcns.c help.c
# Make sure to include stuff from this directory first, to get right "config.h"
# 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
.sh:
@ -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
help.o: vi.h emacs.h common.h help.h fcns.h
fcns.o: vi.h emacs.h common.h help.h fcns.h
# Don't update the files from bitkeeper
%::SCCS/s.%
filecomplete.o: vi.h emacs.h common.h help.h fcns.h

View file

@ -0,0 +1,50 @@
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.

View file

@ -1,269 +0,0 @@
/* $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);
}

View file

@ -1,4 +1,4 @@
/* $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
@ -32,7 +32,13 @@
* 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
@ -40,6 +46,8 @@
#include <stdlib.h>
#include "el.h"
private void ch__clearmacro (EditLine *);
/* value to leave unused in line buffer */
#define EL_LEAVE 2
@ -51,13 +59,13 @@ cv_undo(EditLine *el)
{
c_undo_t *vu = &el->el_chared.c_undo;
c_redo_t *r = &el->el_chared.c_redo;
int size;
unsigned int size;
/* Save entire line for undo */
size = el->el_line.lastchar - el->el_line.buffer;
vu->len = size;
vu->cursor = el->el_line.cursor - el->el_line.buffer;
memcpy(vu->buf, el->el_line.buffer, (size_t)size);
memcpy(vu->buf, el->el_line.buffer, size);
/* save command info for redo */
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))
protected int
ch_init(EditLine *el)
{
c_macro_t *ma = &el->el_chared.c_macro;
el->el_line.buffer = (char *) el_malloc(EL_BUFSIZ);
if (el->el_line.buffer == NULL)
return (-1);
@ -479,11 +489,10 @@ ch_init(EditLine *el)
el->el_state.argument = 1;
el->el_state.lastcmd = ED_UNASSIGNED;
el->el_chared.c_macro.level = -1;
el->el_chared.c_macro.offset = 0;
el->el_chared.c_macro.macro = (char **) el_malloc(EL_MAXMACRO *
sizeof(char *));
if (el->el_chared.c_macro.macro == NULL)
ma->level = -1;
ma->offset = 0;
ma->macro = (char **) el_malloc(EL_MAXMACRO * sizeof(char *));
if (ma->macro == NULL)
return (-1);
return (0);
}
@ -492,7 +501,7 @@ ch_init(EditLine *el)
* Reset the character editor
*/
protected void
ch_reset(EditLine *el)
ch_reset(EditLine *el, int mclear)
{
el->el_line.cursor = el->el_line.buffer;
el->el_line.lastchar = el->el_line.buffer;
@ -513,9 +522,19 @@ ch_reset(EditLine *el)
el->el_state.argument = 1;
el->el_state.lastcmd = ED_UNASSIGNED;
el->el_chared.c_macro.level = -1;
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():
@ -623,9 +642,9 @@ ch_end(EditLine *el)
el->el_chared.c_redo.cmd = ED_UNASSIGNED;
el_free((ptr_t) el->el_chared.c_kill.buf);
el->el_chared.c_kill.buf = NULL;
ch_reset(el, 1);
el_free((ptr_t) el->el_chared.c_macro.macro);
el->el_chared.c_macro.macro = NULL;
ch_reset(el);
}

View file

@ -1,4 +1,4 @@
/* $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
@ -48,7 +48,7 @@
#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
* the cursor.
*
@ -116,11 +116,10 @@ typedef struct el_chared_t {
} el_chared_t;
#define STReof "^D\b\b"
#define STRQQ "\"\""
#define isglob(a) (strchr("*[]?", (a)) != NULL)
#define isword(a) (isprint(a))
#define isword(a) (el_isprint(a))
#define NOP 0x00
#define DELETE 0x01
@ -161,7 +160,7 @@ protected int c_gets(EditLine *, char *, const char *);
protected int c_hpos(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 void ch_end(EditLine *);

View file

@ -1,4 +1,4 @@
/* $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
@ -32,7 +32,13 @@
* 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
@ -130,7 +136,7 @@ ed_delete_prev_word(EditLine *el, int c __attribute__((__unused__)))
*/
protected el_action_t
/*ARGSUSED*/
ed_delete_next_char(EditLine *el, int c __attribute__((__unused__)))
ed_delete_next_char(EditLine *el, int c)
{
#ifdef notdef /* XXX */
#define EL el->el_line
@ -147,9 +153,8 @@ ed_delete_next_char(EditLine *el, int c __attribute__((__unused__)))
#ifdef KSHVI
return (CC_ERROR);
#else
term_overwrite(el, STReof, 4);
/* then do a EOF */
term__flush();
/* then do an EOF */
term_writechar(el, c);
return (CC_EOF);
#endif
} else {
@ -207,13 +212,13 @@ ed_move_to_end(EditLine *el, int c __attribute__((__unused__)))
el->el_line.cursor = el->el_line.lastchar;
if (el->el_map.type == MAP_VI) {
#ifdef VI_MOVE
el->el_line.cursor--;
#endif
if (el->el_chared.c_vcmd.action != NOP) {
cv_delfini(el);
return (CC_REFRESH);
}
#ifdef VI_MOVE
el->el_line.cursor--;
#endif
}
return (CC_CURSOR);
}
@ -609,7 +614,7 @@ protected el_action_t
ed_start_over(EditLine *el, int c __attribute__((__unused__)))
{
ch_reset(el);
ch_reset(el, 0);
return (CC_REFRESH);
}
@ -904,7 +909,7 @@ ed_command(EditLine *el, int c __attribute__((__unused__)))
int tmplen;
tmplen = c_gets(el, tmpbuf, "\n: ");
term__putc('\n');
term__putc(el, '\n');
if (tmplen < 0 || (tmpbuf[tmplen] = 0, parse_line(el, tmpbuf)) == -1)
term_beep(el);

View file

@ -1,43 +0,0 @@
#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

View file

@ -1,2 +0,0 @@
#include "my_config.h"

View file

@ -1,16 +1,2 @@
#include "my_config.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

View file

@ -1,619 +0,0 @@
.\" $NetBSD: editline.3,v 1.21 2001/04/02 18:29:49 wiz Exp $
.\"
.\" Copyright (c) 1997-1999 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This file was contributed to The NetBSD Foundation by Luke Mewburn.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the NetBSD
.\" Foundation, Inc. and its contributors.
.\" 4. Neither the name of The NetBSD Foundation nor the names of its
.\" contributors may be used to endorse or promote products derived
.\" from this software without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd November 12, 1999
.Os
.Dt EDITLINE 3
.Sh NAME
.Nm editline ,
.Nm el_init ,
.Nm el_end ,
.Nm el_reset ,
.Nm el_gets ,
.Nm el_getc ,
.Nm el_push ,
.Nm el_parse ,
.Nm el_set ,
.Nm el_source ,
.Nm el_resize ,
.Nm el_line ,
.Nm el_insertstr ,
.Nm el_deletestr ,
.Nm history_init ,
.Nm history_end ,
.Nm history
.Nd line editor and history functions
.Sh LIBRARY
.Lb libedit
.Sh SYNOPSIS
.Fd #include <histedit.h>
.Ft EditLine *
.Fn el_init "const char *prog" "FILE *fin" "FILE *fout" "FILE *ferr"
.Ft void
.Fn el_end "EditLine *e"
.Ft void
.Fn el_reset "EditLine *e"
.Ft const char *
.Fn el_gets "EditLine *e" "int *count"
.Ft int
.Fn el_getc "EditLine *e" "char *ch"
.Ft void
.Fn el_push "EditLine *e" "const char *str"
.Ft int
.Fn el_parse "EditLine *e" "int argc" "char *argv[]"
.Ft int
.Fn el_set "EditLine *e" "int op" "..."
.Ft int
.Fn el_get "EditLine *e" "int op" "void *result"
.Ft int
.Fn el_source "EditLine *e" "const char *file"
.Ft void
.Fn el_resize "EditLine *e"
.Ft const LineInfo *
.Fn el_line "EditLine *e"
.Ft int
.Fn el_insertstr "EditLine *e" "const char *str"
.Ft void
.Fn el_deletestr "EditLine *e" "int count"
.Ft History *
.Fn history_init
.Ft void
.Fn history_end "History *h"
.Ft int
.Fn history "History *h" "HistEvent *ev" "int op" "..."
.Sh DESCRIPTION
The
.Nm
library provides generic line editing and history functions,
similar to those found in
.Xr sh 1 .
.Pp
These functions are available in the
.Nm libedit
library (which needs the
.Nm libtermcap
library).
Programs should be linked with
.Fl ledit ltermcap .
.Sh LINE EDITING FUNCTIONS
The line editing functions use a common data structure,
.Fa EditLine ,
which is created by
.Fn el_init
and freed by
.Fn el_end .
.Pp
The following functions are available:
.Bl -tag -width 4n
.It Fn el_init
Initialise the line editor, and return a data structure
to be used by all other line editing functions.
.Fa prog
is the name of the invoking program, used when reading the
.Xr editrc 5
file to determine which settings to use.
.Fa fin ,
.Fa fout
and
.Fa ferr
are the input, output, and error streams (respectively) to use.
In this documentation, references to
.Dq the tty
are actually to this input/output stream combination.
.It Fn el_end
Clean up and finish with
.Fa e ,
assumed to have been created with
.Fn el_init .
.It Fn el_reset
Reset the tty and the parser.
This should be called after an error which may have upset the tty's
state.
.It Fn el_gets
Read a line from the tty.
.Fa count
is modified to contain the number of characters read.
Returns the line read if successful, or
.Dv NULL
if no characters were read or if an error occurred.
.It Fn el_getc
Read a character from the tty.
.Fa ch
is modified to contain the character read.
Returns the number of characters read if successful, -1 otherwise.
.It Fn el_push
Pushes
.Fa str
back onto the input stream.
This is used by the macro expansion mechanism.
Refer to the description of
.Ic bind
.Fl s
in
.Xr editrc 5
for more information.
.It Fn el_parse
Parses the
.Fa argv
array (which is
.Fa argc
elements in size)
to execute builtin
.Nm
commands.
If the command is prefixed with
.Dq prog:
then
.Fn el_parse
will only execute the command if
.Dq prog
matches the
.Fa prog
argument supplied to
.Fn el_init .
The return value is
-1 if the command is unknown,
0 if there was no error or
.Dq prog
didn't match, or
1 if the command returned an error.
Refer to
.Xr editrc 5
for more information.
.It Fn el_set
Set
.Nm
parameters.
.Fa op
determines which parameter to set, and each operation has its
own parameter list.
.Pp
The following values for
.Fa op
are supported, along with the required argument list:
.Bl -tag -width 4n
.It Dv EL_PROMPT , Fa "char *(*f)(EditLine *)"
Define prompt printing function as
.Fa f ,
which is to return a string that contains the prompt.
.It Dv EL_RPROMPT , Fa "char *(*f)(EditLine *)"
Define right side prompt printing function as
.Fa f ,
which is to return a string that contains the prompt.
.It Dv EL_TERMINAL , Fa "const char *type"
Define terminal type of the tty to be
.Fa type ,
or to
.Ev TERM
if
.Fa type
is
.Dv NULL .
.It Dv EL_EDITOR , Fa "const char *mode"
Set editing mode to
.Fa mode ,
which must be one of
.Dq emacs
or
.Dq vi .
.It Dv EL_SIGNAL , Fa "int flag"
If
.Fa flag
is non-zero,
.Nm
will install its own signal handler for the following signals when
reading command input:
.Dv SIGCONT ,
.Dv SIGHUP ,
.Dv SIGINT ,
.Dv SIGQUIT ,
.Dv SIGSTOP ,
.Dv SIGTERM ,
.Dv SIGTSTP ,
and
.Dv SIGWINCH .
Otherwise, the current signal handlers will be used.
.It Dv EL_BIND , Xo
.Fa "const char *" ,
.Fa "..." ,
.Dv NULL
.Xc
Perform the
.Ic bind
builtin command.
Refer to
.Xr editrc 5
for more information.
.It Dv EL_ECHOTC , Xo
.Fa "const char *" ,
.Fa "..." ,
.Dv NULL
.Xc
Perform the
.Ic echotc
builtin command.
Refer to
.Xr editrc 5
for more information.
.It Dv EL_SETTC , Xo
.Fa "const char *" ,
.Fa "..." ,
.Dv NULL
.Xc
Perform the
.Ic settc
builtin command.
Refer to
.Xr editrc 5
for more information.
.It Dv EL_SETTY , Xo
.Fa "const char *" ,
.Fa "..." ,
.Dv NULL
.Xc
Perform the
.Ic setty
builtin command.
Refer to
.Xr editrc 5
for more information.
.It Dv EL_TELLTC , Xo
.Fa "const char *" ,
.Fa "..." ,
.Dv NULL
.Xc
Perform the
.Ic telltc
builtin command.
Refer to
.Xr editrc 5
for more information.
.It Dv EL_ADDFN , Xo
.Fa "const char *name" ,
.Fa "const char *help" ,
.Fa "unsigned char (*func)(EditLine *e, int ch)
.Xc
Add a user defined function,
.Fn func ,
referred to as
.Fa name
which is invoked when a key which is bound to
.Fa name
is entered.
.Fa help
is a description of
.Fa name .
At invocation time,
.Fa ch
is the key which caused the invocation.
The return value of
.Fn func
should be one of:
.Bl -tag -width "CC_REDISPLAY"
.It Dv CC_NORM
Add a normal character.
.It Dv CC_NEWLINE
End of line was entered.
.It Dv CC_EOF
EOF was entered.
.It Dv CC_ARGHACK
Expecting further command input as arguments, do nothing visually.
.It Dv CC_REFRESH
Refresh display.
.It Dv CC_REFRESH_BEEP
Refresh display, and beep.
.It Dv CC_CURSOR
Cursor moved, so update and perform
.Dv CC_REFRESH.
.It Dv CC_REDISPLAY
Redisplay entire input line.
This is useful if a key binding outputs extra information.
.It Dv CC_ERROR
An error occurred.
Beep, and flush tty.
.It Dv CC_FATAL
Fatal error, reset tty to known state.
.El
.It Dv EL_HIST , Xo
.Fa "History *(*func)(History *, int op, ...)" ,
.Fa "const char *ptr"
.Xc
Defines which history function to use, which is usually
.Fn history .
.Fa ptr
should be the value returned by
.Fn history_init .
.It Dv EL_EDITMODE , Fa "int flag"
If
.Fa flag
is non-zero,
editing is enabled (the default).
Note that this is only an indication, and does not
affect the operation of
.Nm "" .
At this time, it is the caller's responsibility to
check this
(using
.Fn el_get )
to determine if editing should be enabled or not.
.El
.It Fn el_get
Get
.Nm
parameters.
.Fa op
determines which parameter to retrieve into
.Fa result .
.Pp
The following values for
.Fa op
are supported, along with actual type of
.Fa result :
.Bl -tag -width 4n
.It Dv EL_PROMPT , Fa "char *(*f)(EditLine *)"
Return a pointer to the function that displays the prompt.
.It Dv EL_RPROMPT , Fa "char *(*f)(EditLine *)"
Return a pointer to the function that displays the rightside prompt.
.It Dv EL_EDITOR , Fa "const char *"
Return the name of the editor, which will be one of
.Dq emacs
or
.Dq vi .
.It Dv EL_SIGNAL , Fa "int *"
Return non-zero if
.Nm
has installed private signal handlers (see
.Fn el_get
above).
.It Dv EL_EDITMODE, Fa "int *"
Return non-zero if editing is enabled.
.El
.It Fn el_source
Initialise
.Nm
by reading the contents of
.Fa file .
.Fn el_parse
is called for each line in
.Fa file .
If
.Fa file
is
.Dv NULL ,
try
.Pa $PWD/.editrc
then
.Pa $HOME/.editrc .
Refer to
.Xr editrc 5
for details on the format of
.Fa file .
.It Fn el_resize
Must be called if the terminal size changes.
If
.Dv EL_SIGNAL
has been set with
.Fn el_set ,
then this is done automatically.
Otherwise, it's the responsibility of the application to call
.Fn el_resize
on the appropriate occasions.
.It Fn el_line
Return the editing information for the current line in a
.Fa LineInfo
structure, which is defined as follows:
.Bd -literal
typedef struct lineinfo {
const char *buffer; /* address of buffer */
const char *cursor; /* address of cursor */
const char *lastchar; /* address of last character */
} LineInfo;
.Ed
.It Fn el_insertstr
Insert
.Fa str
into the line at the cursor.
Returns -1 if
.Fa str
is empty or won't fit, and 0 otherwise.
.It Fn el_deletestr
Delete
.Fa num
characters before the cursor.
.El
.Sh HISTORY LIST FUNCTIONS
The history functions use a common data structure,
.Fa History ,
which is created by
.Fn history_init
and freed by
.Fn history_end .
.Pp
The following functions are available:
.Bl -tag -width 4n
.It Fn history_init
Initialise the history list, and return a data structure
to be used by all other history list functions.
.It Fn history_end
Clean up and finish with
.Fa h ,
assumed to have been created with
.Fn history_init .
.It Fn history
Perform operation
.Fa op
on the history list, with optional arguments as needed by the
operation.
.Fa ev
is changed accordingly to operation.
The following values for
.Fa op
are supported, along with the required argument list:
.Bl -tag -width 4n
.It Dv H_SETSIZE , Fa "int size"
Set size of history to
.Fa size
elements.
.It Dv H_GETSIZE
Get number of events currently in history.
.It Dv H_END
Cleans up and finishes with
.Fa h ,
assumed to be created with
.Fn history_init .
.It Dv H_CLEAR
Clear the history.
.It Dv H_FUNC , Xo
.Fa "void *ptr" ,
.Fa "history_gfun_t first" ,
.Fa "history_gfun_t next" ,
.Fa "history_gfun_t last" ,
.Fa "history_gfun_t prev" ,
.Fa "history_gfun_t curr" ,
.Fa "history_sfun_t set" ,
.Fa "history_vfun_t clear" ,
.Fa "history_efun_t enter" ,
.Fa "history_efun_t add"
.Xc
Define functions to perform various history operations.
.Fa ptr
is the argument given to a function when it's invoked.
.It Dv H_FIRST
Return the first element in the history.
.It Dv H_LAST
Return the last element in the history.
.It Dv H_PREV
Return the previous element in the history.
.It Dv H_NEXT
Return the next element in the history.
.It Dv H_CURR
Return the current element in the history.
.It Dv H_SET
Set the cursor to point to the requested element.
.It Dv H_ADD , Fa "const char *str"
Append
.Fa str
to the current element of the history, or create an element with
.It Dv H_APPEND , Fa "const char *str"
Append
.Fa str
to the last new element of the history.
.It Dv H_ENTER , Fa "const char *str"
Add
.Fa str
as a new element to the history, and, if necessary,
removing the oldest entry to keep the list to the created size.
.It Dv H_PREV_STR , Fa "const char *str"
Return the closest previous event that starts with
.Fa str .
.It Dv H_NEXT_STR , Fa "const char *str"
Return the closest next event that starts with
.Fa str .
.It Dv H_PREV_EVENT , Fa "int e"
Return the previous event numbered
.Fa e .
.It Dv H_NEXT_EVENT , Fa "int e"
Return the next event numbered
.Fa e .
.It Dv H_LOAD , Fa "const char *file"
Load the history list stored in
.Fa file .
.It Dv H_SAVE , Fa "const char *file"
Save the history list to
.Fa file .
.El
.Pp
.Fn history
returns 0 if the operation
.Fa op
succeeds. Otherwise, -1 is returned and
.Fa ev
is updated to contain more details about the error.
.El
.\"XXX.Sh EXAMPLES
.\"XXX: provide some examples
.Sh SEE ALSO
.Xr editrc 5 ,
.Xr sh 1 ,
.Xr signal 3 ,
.Xr termcap 3
.Sh HISTORY
The
.Nm
library first appeared in
.Bx 4.4 .
.Dv CC_REDISPLAY
appeared in
.Nx 1.3 .
.Dv CC_REFRESH_BEEP ,
.Dv EL_EDITMODE
and the readline emulation appeared in
.Nx 1.4 .
.Dv EL_RPROMPT
appeared in
.Nx 1.5 .
.Sh AUTHORS
The
.Nm
library was written by Christos Zoulas.
Luke Mewburn wrote this manual and implemented
.Dv CC_REDISPLAY ,
.Dv CC_REFRESH_BEEP ,
.Dv EL_EDITMODE ,
and
.Dv EL_RPROMPT .
Jaromir Dolecek implemented the readline emulation.
.Sh BUGS
The tokenization functions are not publically defined in
.Fd <histedit.h>.
.Pp
At this time, it is the responsibility of the caller to
check the result of the
.Dv EL_EDITMODE
operation of
.Fn el_get
(after an
.Fn el_source
or
.Fn el_parse )
to determine if
.Nm
should be used for further input.
I.e.,
.Dv EL_EDITMODE
is purely an indication of the result of the most recent
.Xr editrc 5
.Ic edit
command.

View file

@ -1,491 +0,0 @@
.\" $NetBSD: editrc.5,v 1.11 2001/06/19 13:42:09 wiz Exp $
.\"
.\" Copyright (c) 1997-2000 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This file was contributed to The NetBSD Foundation by Luke Mewburn.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the NetBSD
.\" Foundation, Inc. and its contributors.
.\" 4. Neither the name of The NetBSD Foundation nor the names of its
.\" contributors may be used to endorse or promote products derived
.\" from this software without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd November 8, 2000
.Os
.Dt EDITRC 5
.Sh NAME
.Nm editrc
.Nd configuration file for editline library
.Sh SYNOPSIS
.Nm
.Sh DESCRIPTION
The
.Nm
file defines various settings to be used by the
.Xr editline 3
library.
.Pp
The format of each line is:
.Dl [prog:]command [arg [...]]
.Pp
.Ar command
is one of the
.Xr editline 3
builtin commands.
Refer to
.Sx BUILTIN COMMANDS
for more information.
.Pp
.Ar prog
is the program name string that a program defines when it calls
.Xr el_init 3
to setup
.Xr editline 3 ,
which is usually
.Va argv[0] .
.Ar command
will be executed for any program which matches
.Ar prog .
.Pp
.Ar prog
may also be a
.Xr regex 3
style
regular expression, in which case
.Ar command
will be executed for any program that matches the regular expression.
.Pp
If
.Ar prog
is absent,
.Ar command
is executed for all programs.
.Sh BUILTIN COMMANDS
The
.Nm editline
library has some builtin commands, which affect the way
that the line editing and history functions operate.
These are based on similar named builtins present in the
.Xr tcsh 1
shell.
.Pp
The following builtin commands are available:
.Bl -tag -width 4n
.It Ic bind Xo
.Op Fl a
.Op Fl e
.Op Fl k
.Op Fl l
.Op Fl r
.Op Fl s
.Op Fl v
.Op Ar key Op Ar command
.Xc
Without options, list all bound keys, and the editor command to which
each is bound.
If
.Ar key
is supplied, show the bindings for
.Ar key .
If
.Ar key command
is supplied, bind
.Ar command
to
.Ar key .
Options include:
.Bl -tag -width 4n
.It Fl e
Bind all keys to the standard GNU Emacs-like bindings.
.It Fl v
Bind all keys to the standard
.Xr vi 1 -like
bindings.
.It Fl a
List or change key bindings in the
.Xr vi 1
mode alternate (command mode) key map.
.It Fl k
.Ar key
is interpreted as a symbolic arrow key name, which may be one of
.Sq up ,
.Sq down ,
.Sq left
or
.Sq right .
.It Fl l
List all editor commands and a short description of each.
.It Fl r
Remove a key's binding.
.It Fl s
.Ar command
is taken as a literal string and treated as terminal input when
.Ar key
is typed.
Bound keys in
.Ar command
are themselves reinterpreted, and this continues for ten levels of
interpretation.
.El
.Pp
.Ar command
may be one of the commands documented in
.Sx "EDITOR COMMANDS"
below, or another key.
.Pp
.Ar key
and
.Ar command
can contain control characters of the form
.Sm off
.Sq No ^ Ar character
.Sm on
.Po
e.g.
.Sq ^A
.Pc ,
and the following backslashed escape sequences:
.Pp
.Bl -tag -compact -offset indent -width 4n
.It Ic \ea
Bell
.It Ic \eb
Backspace
.It Ic \ee
Escape
.It Ic \ef
Formfeed
.It Ic \en
Newline
.It Ic \er
Carriage return
.It Ic \et
Horizontal tab
.It Ic \ev
Vertical tab
.Sm off
.It Sy \e Ar nnn
.Sm on
The ASCII character corresponding to the octal number
.Ar nnn .
.El
.Pp
.Sq \e
nullifies the special meaning of the following character,
if it has any, notably
.Sq \e
and
.Sq ^ .
.It Ic echotc Xo
.Op Fl sv
.Ar arg
.Ar ...
.Xc
Exercise terminal capabilities given in
.Ar arg Ar ... .
If
.Ar arg
is
.Sq baud ,
.Sq cols ,
.Sq lines ,
.Sq rows ,
.Sq meta or
.Sq tabs ,
the value of that capability is printed, with
.Dq yes
or
.Dq no
indicating that the terminal does or does not have that capability.
.Pp
.Fl s
returns an emptry string for non-existent capabilities, rather than
causing an error.
.Fl v
causes messages to be verbose.
.It Ic edit Op Li on | Li off
Enable or disable the
.Nm editline
functionality in a program.
.It Ic history
List the history.
.It Ic telltc
List the values of all the terminal capabilities (see
.Xr termcap 5 ).
.It Ic settc Ar cap Ar val
Set the terminal capability
.Ar cap
to
.Ar val ,
as defined in
.Xr termcap 5 .
No sanity checking is done.
.It Ic setty Xo
.Op Fl a
.Op Fl d
.Op Fl q
.Op Fl x
.Op Ar +mode
.Op Ar -mode
.Op Ar mode
.Xc
Control which tty modes that
.Nm
won't allow the user to change.
.Fl d ,
.Fl q
or
.Fl x
tells
.Ic setty
to act on the
.Sq edit ,
.Sq quote
or
.Sq execute
set of tty modes respectively; defaulting to
.Fl x .
.Pp
Without other arguments,
.Ic setty
lists the modes in the chosen set which are fixed on
.Po
.Sq +mode
.Pc
or off
.Po
.Sq -mode
.Pc .
.Fl a
lists all tty modes in the chosen set regardless of the setting.
With
.Ar +mode ,
.Ar -mode
or
.Ar mode ,
fixes
.Ar mode
on or off or removes control of
.Ar mode
in the chosen set.
.El
.Sh EDITOR COMMANDS
The following editor commands are available for use in key bindings:
.\" Section automatically generated with makelist
.Bl -tag -width 4n
.It Ic vi-paste-next
Vi paste previous deletion to the right of the cursor.
.It Ic vi-paste-prev
Vi paste previous deletion to the left of the cursor.
.It Ic vi-prev-space-word
Vi move to the previous space delimited word.
.It Ic vi-prev-word
Vi move to the previous word.
.It Ic vi-next-space-word
Vi move to the next space delimited word.
.It Ic vi-next-word
Vi move to the next word.
.It Ic vi-change-case
Vi change case of character under the cursor and advance one character.
.It Ic vi-change-meta
Vi change prefix command.
.It Ic vi-insert-at-bol
Vi enter insert mode at the beginning of line.
.It Ic vi-replace-char
Vi replace character under the cursor with the next character typed.
.It Ic vi-replace-mode
Vi enter replace mode.
.It Ic vi-substitute-char
Vi replace character under the cursor and enter insert mode.
.It Ic vi-substitute-line
Vi substitute entire line.
.It Ic vi-change-to-eol
Vi change to end of line.
.It Ic vi-insert
Vi enter insert mode.
.It Ic vi-add
Vi enter insert mode after the cursor.
.It Ic vi-add-at-eol
Vi enter insert mode at end of line.
.It Ic vi-delete-meta
Vi delete prefix command.
.It Ic vi-end-word
Vi move to the end of the current space delimited word.
.It Ic vi-to-end-word
Vi move to the end of the current word.
.It Ic vi-undo
Vi undo last change.
.It Ic vi-command-mode
Vi enter command mode (use alternative key bindings).
.It Ic vi-zero
Vi move to the beginning of line.
.It Ic vi-delete-prev-char
Vi move to previous character (backspace).
.It Ic vi-list-or-eof
Vi list choices for completion or indicate end of file if empty line.
.It Ic vi-kill-line-prev
Vi cut from beginning of line to cursor.
.It Ic vi-search-prev
Vi search history previous.
.It Ic vi-search-next
Vi search history next.
.It Ic vi-repeat-search-next
Vi repeat current search in the same search direction.
.It Ic vi-repeat-search-prev
Vi repeat current search in the opposite search direction.
.It Ic vi-next-char
Vi move to the character specified next.
.It Ic vi-prev-char
Vi move to the character specified previous.
.It Ic vi-to-next-char
Vi move up to the character specified next.
.It Ic vi-to-prev-char
Vi move up to the character specified previous.
.It Ic vi-repeat-next-char
Vi repeat current character search in the same search direction.
.It Ic vi-repeat-prev-char
Vi repeat current character search in the opposite search direction.
.It Ic em-delete-or-list
Delete character under cursor or list completions if at end of line.
.It Ic em-delete-next-word
Cut from cursor to end of current word.
.It Ic em-yank
Paste cut buffer at cursor position.
.It Ic em-kill-line
Cut the entire line and save in cut buffer.
.It Ic em-kill-region
Cut area between mark and cursor and save in cut buffer.
.It Ic em-copy-region
Copy area between mark and cursor to cut buffer.
.It Ic em-gosmacs-traspose
Exchange the two characters before the cursor.
.It Ic em-next-word
Move next to end of current word.
.It Ic em-upper-case
Uppercase the characters from cursor to end of current word.
.It Ic em-capitol-case
Capitalize the characters from cursor to end of current word.
.It Ic em-lower-case
Lowercase the characters from cursor to end of current word.
.It Ic em-set-mark
Set the mark at cursor.
.It Ic em-exchange-mark
Exchange the cursor and mark.
.It Ic em-universal-argument
Universal argument (argument times 4).
.It Ic em-meta-next
Add 8th bit to next character typed.
.It Ic em-toggle-overwrite
Switch from insert to overwrite mode or vice versa.
.It Ic em-copy-prev-word
Copy current word to cursor.
.It Ic em-inc-search-next
Emacs incremental next search.
.It Ic em-inc-search-prev
Emacs incremental reverse search.
.It Ic ed-end-of-file
Indicate end of file.
.It Ic ed-insert
Add character to the line.
.It Ic ed-delete-prev-word
Delete from beginning of current word to cursor.
.It Ic ed-delete-next-char
Delete character under cursor.
.It Ic ed-kill-line
Cut to the end of line.
.It Ic ed-move-to-end
Move cursor to the end of line.
.It Ic ed-move-to-beg
Move cursor to the beginning of line.
.It Ic ed-transpose-chars
Exchange the character to the left of the cursor with the one under it.
.It Ic ed-next-char
Move to the right one character.
.It Ic ed-prev-word
Move to the beginning of the current word.
.It Ic ed-prev-char
Move to the left one character.
.It Ic ed-quoted-insert
Add the next character typed verbatim.
.It Ic ed-digit
Adds to argument or enters a digit.
.It Ic ed-argument-digit
Digit that starts argument.
.It Ic ed-unassigned
Indicates unbound character.
.It Ic ed-tty-sigint
Tty interrupt character.
.It Ic ed-tty-dsusp
Tty delayed suspend character.
.It Ic ed-tty-flush-output
Tty flush output characters.
.It Ic ed-tty-sigquit
Tty quit character.
.It Ic ed-tty-sigtstp
Tty suspend character.
.It Ic ed-tty-stop-output
Tty disallow output characters.
.It Ic ed-tty-start-output
Tty allow output characters.
.It Ic ed-newline
Execute command.
.It Ic ed-delete-prev-char
Delete the character to the left of the cursor.
.It Ic ed-clear-screen
Clear screen leaving current line at the top.
.It Ic ed-redisplay
Redisplay everything.
.It Ic ed-start-over
Erase current line and start from scratch.
.It Ic ed-sequence-lead-in
First character in a bound sequence.
.It Ic ed-prev-history
Move to the previous history line.
.It Ic ed-next-history
Move to the next history line.
.It Ic ed-search-prev-history
Search previous in history for a line matching the current.
.It Ic ed-search-next-history
Search next in history for a line matching the current.
.It Ic ed-prev-line
Move up one line.
.It Ic ed-next-line
Move down one line.
.It Ic ed-command
Editline extended command.
.El
.\" End of section automatically generated with makelist
.Sh SEE ALSO
.Xr editline 3 ,
.Xr regex 3 ,
.Xr termcap 5
.Sh AUTHORS
The
.Nm editline
library was written by Christos Zoulas,
and this manual was written by Luke Mewburn,
with some sections inspired by
.Xr tcsh 1 .

View file

@ -1,4 +1,4 @@
/* $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
@ -32,7 +32,13 @@
* 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
@ -58,9 +64,12 @@ el_init(const char *prog, FILE *fin, FILE *fout, FILE *ferr)
memset(el, 0, sizeof(EditLine));
el->el_infd = fileno(fin);
el->el_infile = fin;
el->el_outfile = fout;
el->el_errfile = ferr;
el->el_infd = fileno(fin);
if ((el->el_prog = el_strdup(prog)) == NULL) {
el_free(el);
return NULL;
@ -126,7 +135,7 @@ el_reset(EditLine *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)
public int
el_set(EditLine *el, int op, ...)
{
va_list va;
va_list ap;
int rv = 0;
if (el == NULL)
return (-1);
va_start(va, op);
va_start(ap, op);
switch (op) {
case EL_PROMPT:
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;
case EL_TERMINAL:
rv = term_set(el, va_arg(va, char *));
rv = term_set(el, va_arg(ap, char *));
break;
case EL_EDITOR:
rv = map_set_editor(el, va_arg(va, char *));
rv = map_set_editor(el, va_arg(ap, char *));
break;
case EL_SIGNAL:
if (va_arg(va, int))
if (va_arg(ap, int))
el->el_flags |= HANDLE_SIGNALS;
else
el->el_flags &= ~HANDLE_SIGNALS;
@ -167,6 +176,7 @@ el_set(EditLine *el, int op, ...)
case EL_BIND:
case EL_TELLTC:
case EL_SETTC:
case EL_GETTC:
case EL_ECHOTC:
case EL_SETTY:
{
@ -174,7 +184,7 @@ el_set(EditLine *el, int op, ...)
int i;
for (i = 1; i < 20; i++)
if ((argv[i] = va_arg(va, char *)) == NULL)
if ((argv[i] = va_arg(ap, char *)) == NULL)
break;
switch (op) {
@ -213,9 +223,9 @@ el_set(EditLine *el, int op, ...)
case EL_ADDFN:
{
char *name = va_arg(va, char *);
char *help = va_arg(va, char *);
el_func_t func = va_arg(va, el_func_t);
char *name = va_arg(ap, char *);
char *help = va_arg(ap, char *);
el_func_t func = va_arg(ap, el_func_t);
rv = map_addfunc(el, name, help, func);
break;
@ -223,15 +233,15 @@ el_set(EditLine *el, int op, ...)
case EL_HIST:
{
hist_fun_t func = va_arg(va, hist_fun_t);
ptr_t ptr = va_arg(va, char *);
hist_fun_t func = va_arg(ap, hist_fun_t);
ptr_t ptr = va_arg(ap, char *);
rv = hist_set(el, func, ptr);
break;
}
case EL_EDITMODE:
if (va_arg(va, int))
if (va_arg(ap, int))
el->el_flags &= ~EDIT_DISABLED;
else
el->el_flags |= EDIT_DISABLED;
@ -240,17 +250,17 @@ el_set(EditLine *el, int op, ...)
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);
break;
}
case EL_CLIENTDATA:
el->el_data = va_arg(va, void *);
el->el_data = va_arg(ap, void *);
break;
case EL_UNBUFFERED:
rv = va_arg(va, int);
rv = va_arg(ap, int);
if (rv && !(el->el_flags & UNBUFFERED)) {
el->el_flags |= UNBUFFERED;
read_prepare(el);
@ -262,7 +272,7 @@ el_set(EditLine *el, int op, ...)
break;
case EL_PREP_TERM:
rv = va_arg(va, int);
rv = va_arg(ap, int);
if (rv)
(void) tty_rawmode(el);
else
@ -270,12 +280,45 @@ el_set(EditLine *el, int op, ...)
rv = 0;
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:
rv = -1;
break;
}
va_end(va);
va_end(ap);
return (rv);
}
@ -284,90 +327,71 @@ el_set(EditLine *el, int op, ...)
* retrieve the editline parameters
*/
public int
el_get(EditLine *el, int op, void *ret)
el_get(EditLine *el, int op, ...)
{
va_list ap;
int rv;
if (el == NULL || ret == NULL)
return (-1);
if (el == NULL)
return -1;
va_start(ap, op);
switch (op) {
case EL_PROMPT:
case EL_RPROMPT:
rv = prompt_get(el, (void *) &ret, op);
rv = prompt_get(el, va_arg(ap, el_pfunc_t *), op);
break;
case EL_EDITOR:
rv = map_get_editor(el, (void *) &ret);
rv = map_get_editor(el, va_arg(ap, const char **));
break;
case EL_SIGNAL:
*((int *) ret) = (el->el_flags & HANDLE_SIGNALS);
*va_arg(ap, int *) = (el->el_flags & HANDLE_SIGNALS);
rv = 0;
break;
case EL_EDITMODE:
*((int *) ret) = (!(el->el_flags & EDIT_DISABLED));
*va_arg(ap, int *) = !(el->el_flags & EDIT_DISABLED);
rv = 0;
break;
case EL_TERMINAL:
term_get(el, (const char **)ret);
term_get(el, va_arg(ap, const char **));
rv = 0;
break;
#if 0 /* XXX */
case EL_BIND:
case EL_TELLTC:
case EL_SETTC:
case EL_ECHOTC:
case EL_SETTY:
case EL_GETTC:
{
const char *argv[20];
static char name[] = "gettc";
char *argv[20];
int i;
for (i = 1; i < sizeof(argv) / sizeof(argv[0]); i++)
if ((argv[i] = va_arg(va, char *)) == NULL)
for (i = 1; i < (int)(sizeof(argv) / sizeof(argv[0])); i++)
if ((argv[i] = va_arg(ap, char *)) == NULL)
break;
switch (op) {
case EL_BIND:
argv[0] = "bind";
rv = map_bind(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);
case EL_GETTC:
argv[0] = name;
rv = term_gettc(el, i, argv);
break;
default:
rv = -1;
EL_ABORT((el->errfile, "Bad op %d\n", op));
EL_ABORT((el->el_errfile, "Bad op %d\n", op));
break;
}
break;
}
#if 0 /* XXX */
case EL_ADDFN:
{
char *name = va_arg(va, char *);
char *help = va_arg(va, char *);
el_func_t func = va_arg(va, el_func_t);
char *name = va_arg(ap, char *);
char *help = va_arg(ap, char *);
el_func_t func = va_arg(ap, el_func_t);
rv = map_addfunc(el, name, help, func);
break;
@ -375,31 +399,57 @@ el_get(EditLine *el, int op, void *ret)
case EL_HIST:
{
hist_fun_t func = va_arg(va, hist_fun_t);
ptr_t ptr = va_arg(va, char *);
hist_fun_t func = va_arg(ap, hist_fun_t);
ptr_t ptr = va_arg(ap, char *);
rv = hist_set(el, func, ptr);
}
break;
#endif /* XXX */
case EL_GETCFN:
*((el_rfunc_t *)ret) = el_read_getfn(el);
*va_arg(ap, el_rfunc_t *) = el_read_getfn(el);
rv = 0;
break;
case EL_CLIENTDATA:
*((void **)ret) = el->el_data;
*va_arg(ap, void **) = el->el_data;
rv = 0;
break;
case EL_UNBUFFERED:
*((int *) ret) = (!(el->el_flags & UNBUFFERED));
*va_arg(ap, int *) = (!(el->el_flags & UNBUFFERED));
rv = 0;
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:
rv = -1;
break;
}
va_end(ap);
return (rv);
}
@ -428,17 +478,17 @@ el_source(EditLine *el, const char *fname)
fp = NULL;
if (fname == NULL) {
#ifdef HAVE_ISSETUGID
static const char elpath[] = "/.editrc";
/* XXXMYSQL: Portability fix (for which platforms?) */
#ifdef MAXPATHLEN
char path[MAXPATHLEN];
#else
char path[4096];
#endif
#ifdef HAVE_ISSETUGID
if (issetugid())
return (-1);
#endif
if ((ptr = getenv("HOME")) == NULL)
return (-1);
if (strlcpy(path, ptr, sizeof(path)) >= sizeof(path))
@ -446,6 +496,14 @@ el_source(EditLine *el, const char *fname)
if (strlcat(path, elpath, sizeof(path)) >= sizeof(path))
return (-1);
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)
fp = fopen(fname, "r");

View file

@ -1,4 +1,4 @@
/* $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
@ -110,6 +110,7 @@ typedef struct el_state_t {
struct editline {
char *el_prog; /* the program name */
FILE *el_infile; /* Stdio stuff */
FILE *el_outfile; /* Stdio stuff */
FILE *el_errfile; /* Stdio stuff */
int el_infd; /* Input file descriptor */
@ -136,7 +137,8 @@ struct editline {
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
#define EL_ABORT(a) do { \

View file

@ -1,4 +1,4 @@
/* $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
@ -81,25 +81,6 @@ typedef struct {
#define A_K_EN 5
#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_char(EditLine *, int);
protected void term_clear_EOL(EditLine *, int);
@ -119,10 +100,12 @@ protected void term_end(EditLine *);
protected void term_get(EditLine *, const char **);
protected int term_set(EditLine *, 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_echotc(EditLine *, int, const char **);
protected int term__putc(int);
protected void term__flush(void);
protected void term_writec(EditLine *, int);
protected int term__putc(EditLine *, int);
protected void term__flush(EditLine *);
/*
* Easy access macros
@ -134,6 +117,7 @@ protected void term__flush(void);
#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_CAN_UP (EL_FLAGS & TERM_CAN_UP)
#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)

View file

@ -1,4 +1,4 @@
/* $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
@ -32,7 +32,13 @@
* 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
@ -45,15 +51,14 @@
*/
protected el_action_t
/*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 I'm at the end */
if (el->el_line.cursor == el->el_line.buffer) {
/* and the beginning */
term_overwrite(el, STReof, 4); /* then do a EOF */
term__flush();
term_writec(el, c); /* then do an EOF */
return (CC_EOF);
} else {
/*

View file

@ -1,3 +0,0 @@
#include <stdio.h>
char *fgetln(FILE *stream, size_t *len);

View file

@ -0,0 +1,558 @@
/* $NetBSD: filecomplete.c,v 1.13 2009/01/26 17:32:41 apb Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jaromir Dolecek.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/* AIX requires this to be the first thing in the file. */
#if defined (_AIX) && !defined (__GNUC__)
#pragma alloca
#endif
#include "config.h"
/* XXXMYSQL */
#ifdef __GNUC__
# undef alloca
# define alloca(n) __builtin_alloca (n)
#else
# ifdef HAVE_ALLOCA_H
# include <alloca.h>
# else
# ifndef _AIX
extern char *alloca ();
# endif
# endif
#endif
#if !defined(lint) && !defined(SCCSID)
#endif /* not lint && not SCCSID */
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <dirent.h>
#include <string.h>
#include <pwd.h>
#include <ctype.h>
#include <stdlib.h>
#include <unistd.h>
#include <limits.h>
#include <errno.h>
#include <fcntl.h>
#ifdef HAVE_VIS_H
#include <vis.h>
#else
#include "np/vis.h"
#endif
#ifdef HAVE_ALLOCA_H
#include <alloca.h>
#endif
#include "el.h"
#include "fcns.h" /* for EL_NUM_FCNS */
#include "histedit.h"
#include "filecomplete.h"
static char break_chars[] = { ' ', '\t', '\n', '"', '\\', '\'', '`', '@', '$',
'>', '<', '=', ';', '|', '&', '{', '(', '\0' };
/********************************/
/* completion functions */
/*
* does tilde expansion of strings of type ``~user/foo''
* if ``user'' isn't valid user name or ``txt'' doesn't start
* w/ '~', returns pointer to strdup()ed copy of ``txt''
*
* it's callers's responsibility to free() returned string
*/
char *
fn_tilde_expand(const char *txt)
{
struct passwd pwres, *pass;
char *temp;
size_t len = 0;
char pwbuf[1024];
if (txt[0] != '~')
return (strdup(txt));
temp = strchr(txt + 1, '/');
if (temp == NULL) {
temp = strdup(txt + 1);
if (temp == NULL)
return NULL;
} else {
len = temp - txt + 1; /* text until string after slash */
temp = malloc(len);
if (temp == NULL)
return NULL;
(void)strncpy(temp, txt + 1, len - 2);
temp[len - 2] = '\0';
}
/* XXXMYSQL: use non-_r functions for now */
if (temp[0] == 0) {
pass = getpwuid(getuid());
} else {
pass = getpwnam(temp);
}
free(temp); /* value no more needed */
if (pass == NULL)
return (strdup(txt));
/* update pointer txt to point at string immedially following */
/* first slash */
txt += len;
temp = malloc(strlen(pass->pw_dir) + 1 + strlen(txt) + 1);
if (temp == NULL)
return NULL;
(void)sprintf(temp, "%s/%s", pass->pw_dir, txt);
return (temp);
}
/*
* return first found file name starting by the ``text'' or NULL if no
* such file can be found
* value of ``state'' is ignored
*
* it's caller's responsibility to free returned string
*/
char *
fn_filename_completion_function(const char *text, int state)
{
static DIR *dir = NULL;
static char *filename = NULL, *dirname = NULL, *dirpath = NULL;
static size_t filename_len = 0;
struct dirent *entry;
char *temp;
size_t len;
if (state == 0 || dir == NULL) {
temp = strrchr(text, '/');
if (temp) {
char *nptr;
temp++;
nptr = realloc(filename, strlen(temp) + 1);
if (nptr == NULL) {
free(filename);
return NULL;
}
filename = nptr;
(void)strcpy(filename, temp);
len = temp - text; /* including last slash */
nptr = realloc(dirname, len + 1);
if (nptr == NULL) {
free(filename);
return NULL;
}
dirname = nptr;
(void)strncpy(dirname, text, len);
dirname[len] = '\0';
} else {
if (*text == 0)
filename = NULL;
else {
filename = strdup(text);
if (filename == NULL)
return NULL;
}
dirname = NULL;
}
if (dir != NULL) {
(void)closedir(dir);
dir = NULL;
}
/* support for ``~user'' syntax */
free(dirpath);
if (dirname == NULL && (dirname = strdup("./")) == NULL)
return NULL;
if (*dirname == '~')
dirpath = fn_tilde_expand(dirname);
else
dirpath = strdup(dirname);
if (dirpath == NULL)
return NULL;
dir = opendir(dirpath);
if (!dir)
return (NULL); /* cannot open the directory */
/* will be used in cycle */
filename_len = filename ? strlen(filename) : 0;
}
/* find the match */
while ((entry = readdir(dir)) != NULL) {
/* skip . and .. */
if (entry->d_name[0] == '.' && (!entry->d_name[1]
|| (entry->d_name[1] == '.' && !entry->d_name[2])))
continue;
if (filename_len == 0)
break;
/* otherwise, get first entry where first */
/* filename_len characters are equal */
if (entry->d_name[0] == filename[0]
#if HAVE_STRUCT_DIRENT_D_NAMLEN
&& entry->d_namlen >= filename_len
#else
&& strlen(entry->d_name) >= filename_len
#endif
&& strncmp(entry->d_name, filename,
filename_len) == 0)
break;
}
if (entry) { /* match found */
#if HAVE_STRUCT_DIRENT_D_NAMLEN
len = entry->d_namlen;
#else
len = strlen(entry->d_name);
#endif
temp = malloc(strlen(dirname) + len + 1);
if (temp == NULL)
return NULL;
(void)sprintf(temp, "%s%s", dirname, entry->d_name);
} else {
(void)closedir(dir);
dir = NULL;
temp = NULL;
}
return (temp);
}
static const char *
append_char_function(const char *name)
{
struct stat stbuf;
char *expname = *name == '~' ? fn_tilde_expand(name) : NULL;
const char *rs = " ";
if (stat(expname ? expname : name, &stbuf) == -1)
goto out;
if (S_ISDIR(stbuf.st_mode))
rs = "/";
out:
if (expname)
free(expname);
return rs;
}
/*
* returns list of completions for text given
* non-static for readline.
*/
char ** completion_matches(const char *, char *(*)(const char *, int));
char **
completion_matches(const char *text, char *(*genfunc)(const char *, int))
{
char **match_list = NULL, *retstr, *prevstr;
size_t match_list_len, max_equal, which, i;
size_t matches;
matches = 0;
match_list_len = 1;
while ((retstr = (*genfunc) (text, (int)matches)) != NULL) {
/* allow for list terminator here */
if (matches + 3 >= match_list_len) {
char **nmatch_list;
while (matches + 3 >= match_list_len)
match_list_len <<= 1;
nmatch_list = realloc(match_list,
match_list_len * sizeof(char *));
if (nmatch_list == NULL) {
free(match_list);
return NULL;
}
match_list = nmatch_list;
}
match_list[++matches] = retstr;
}
if (!match_list)
return NULL; /* nothing found */
/* find least denominator and insert it to match_list[0] */
which = 2;
prevstr = match_list[1];
max_equal = strlen(prevstr);
for (; which <= matches; which++) {
for (i = 0; i < max_equal &&
prevstr[i] == match_list[which][i]; i++)
continue;
max_equal = i;
}
retstr = malloc(max_equal + 1);
if (retstr == NULL) {
free(match_list);
return NULL;
}
(void)strncpy(retstr, match_list[1], max_equal);
retstr[max_equal] = '\0';
match_list[0] = retstr;
/* add NULL as last pointer to the array */
match_list[matches + 1] = (char *) NULL;
return (match_list);
}
/*
* Sort function for qsort(). Just wrapper around strcasecmp().
*/
static int
_fn_qsort_string_compare(const void *i1, const void *i2)
{
const char *s1 = ((const char * const *)i1)[0];
const char *s2 = ((const char * const *)i2)[0];
return strcasecmp(s1, s2);
}
/*
* Display list of strings in columnar format on readline's output stream.
* 'matches' is list of strings, 'len' is number of strings in 'matches',
* 'max' is maximum length of string in 'matches'.
*/
void
fn_display_match_list (EditLine *el, char **matches, int len, int max)
{
int i, idx, limit, count;
int screenwidth = el->el_term.t_size.h;
/*
* Find out how many entries can be put on one line, count
* with two spaces between strings.
*/
limit = screenwidth / (max + 2);
if (limit == 0)
limit = 1;
/* how many lines of output */
count = len / limit;
if (count * limit < len)
count++;
/* Sort the items if they are not already sorted. */
qsort(&matches[1], (size_t)(len - 1), sizeof(char *),
_fn_qsort_string_compare);
idx = 1;
for(; count > 0; count--) {
for(i = 0; i < limit && matches[idx]; i++, idx++)
(void)fprintf(el->el_outfile, "%-*s ", max,
matches[idx]);
(void)fprintf(el->el_outfile, "\n");
}
}
/*
* Complete the word at or before point,
* 'what_to_do' says what to do with the completion.
* \t means do standard completion.
* `?' means list the possible completions.
* `*' means insert all of the possible completions.
* `!' means to do standard completion, and list all possible completions if
* there is more than one.
*
* Note: '*' support is not implemented
* '!' could never be invoked
*/
int
fn_complete(EditLine *el,
char *(*complet_func)(const char *, int),
char **(*attempted_completion_function)(const char *, int, int),
const char *word_break, const char *special_prefixes,
const char *(*app_func)(const char *), int query_items,
int *completion_type, int *over, int *point, int *end)
{
const LineInfo *li;
char *temp, **matches;
const char *ctemp;
size_t len;
int what_to_do = '\t';
int retval = CC_NORM;
if (el->el_state.lastcmd == el->el_state.thiscmd)
what_to_do = '?';
/* readline's rl_complete() has to be told what we did... */
if (completion_type != NULL)
*completion_type = what_to_do;
if (!complet_func)
complet_func = fn_filename_completion_function;
if (!app_func)
app_func = append_char_function;
/* We now look backwards for the start of a filename/variable word */
li = el_line(el);
ctemp = (const char *) li->cursor;
while (ctemp > li->buffer
&& !strchr(word_break, ctemp[-1])
&& (!special_prefixes || !strchr(special_prefixes, ctemp[-1]) ) )
ctemp--;
len = li->cursor - ctemp;
#if defined(__SSP__) || defined(__SSP_ALL__)
temp = malloc(len + 1);
#else
temp = alloca(len + 1);
#endif
(void)strncpy(temp, ctemp, len);
temp[len] = '\0';
/* these can be used by function called in completion_matches() */
/* or (*attempted_completion_function)() */
if (point != 0)
*point = li->cursor - li->buffer;
if (end != NULL)
*end = li->lastchar - li->buffer;
if (attempted_completion_function) {
int cur_off = li->cursor - li->buffer;
matches = (*attempted_completion_function) (temp,
(int)(cur_off - len), cur_off);
} else
matches = 0;
if (!attempted_completion_function ||
(over != NULL && !*over && !matches))
matches = completion_matches(temp, complet_func);
if (over != NULL)
*over = 0;
if (matches) {
int i;
int matches_num, maxlen, match_len, match_display=1;
retval = CC_REFRESH;
/*
* Only replace the completed string with common part of
* possible matches if there is possible completion.
*/
if (matches[0][0] != '\0') {
el_deletestr(el, (int) len);
el_insertstr(el, matches[0]);
}
if (what_to_do == '?')
goto display_matches;
if (matches[2] == NULL && strcmp(matches[0], matches[1]) == 0) {
/*
* We found exact match. Add a space after
* it, unless we do filename completion and the
* object is a directory.
*/
el_insertstr(el, (*app_func)(matches[0]));
} else if (what_to_do == '!') {
display_matches:
/*
* More than one match and requested to list possible
* matches.
*/
for(i=1, maxlen=0; matches[i]; i++) {
match_len = strlen(matches[i]);
if (match_len > maxlen)
maxlen = match_len;
}
matches_num = i - 1;
/* newline to get on next line from command line */
(void)fprintf(el->el_outfile, "\n");
/*
* If there are too many items, ask user for display
* confirmation.
*/
if (matches_num > query_items) {
(void)fprintf(el->el_outfile,
"Display all %d possibilities? (y or n) ",
matches_num);
(void)fflush(el->el_outfile);
if (getc(stdin) != 'y')
match_display = 0;
(void)fprintf(el->el_outfile, "\n");
}
if (match_display)
fn_display_match_list(el, matches, matches_num,
maxlen);
retval = CC_REDISPLAY;
} else if (matches[0][0]) {
/*
* There was some common match, but the name was
* not complete enough. Next tab will print possible
* completions.
*/
el_beep(el);
} else {
/* lcd is not a valid object - further specification */
/* is needed */
el_beep(el);
retval = CC_NORM;
}
/* free elements of array and the array itself */
for (i = 0; matches[i]; i++)
free(matches[i]);
free(matches);
matches = NULL;
}
#if defined(__SSP__) || defined(__SSP_ALL__)
free(temp);
#endif
return retval;
}
/*
* el-compatible wrapper around rl_complete; needed for key binding
*/
/* ARGSUSED */
unsigned char
_el_fn_complete(EditLine *el, int ch __attribute__((__unused__)))
{
return (unsigned char)fn_complete(el, NULL, NULL,
break_chars, NULL, NULL, 100,
NULL, NULL, NULL, NULL);
}

View file

@ -1,11 +1,11 @@
/* $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.
*
* 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
* modification, are permitted provided that the following conditions
@ -15,13 +15,6 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
@ -35,54 +28,17 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _FILECOMPLETE_H_
#define _FILECOMPLETE_H_
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
int fn_complete(EditLine *,
char *(*)(const char *, int),
char **(*)(const char *, int, int),
const char *, const char *, const char *(*)(const char *), int,
int *, int *, int *, int *);
void fn_display_match_list(EditLine *, char **, int, int);
char *fn_tilde_expand(const char *);
char *fn_filename_completion_function(const char *, int);
char *
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;
}
#endif

View file

@ -32,7 +32,13 @@
* 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

View file

@ -1,4 +1,4 @@
/* $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
@ -41,11 +41,15 @@
#define _HISTEDIT_H_
#define LIBEDIT_MAJOR 2
#define LIBEDIT_MINOR 9
#define LIBEDIT_MINOR 11
#include <sys/types.h>
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* ==== Editing ====
*/
@ -88,7 +92,7 @@ void el_reset(EditLine *);
*/
const char *el_gets(EditLine *, int *);
int el_getc(EditLine *, char *);
void el_push(EditLine *, char *);
void el_push(EditLine *, const char *);
/*
* Beep!
@ -105,7 +109,8 @@ int el_parse(EditLine *, int, const char **);
* Low level editline access functions
*/
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
@ -128,8 +133,12 @@ int el_get(EditLine *, int, void *);
#define EL_CLIENTDATA 14 /* , void *); */
#define EL_UNBUFFERED 15 /* , 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
@ -192,6 +201,7 @@ int history(History *, HistEvent *, int, ...);
#define H_CLEAR 19 /* , void); */
#define H_SETUNIQUE 20 /* , int); */
#define H_GETUNIQUE 21 /* , void); */
#define H_DEL 22 /* , int); */
/*
@ -211,4 +221,8 @@ int tok_line(Tokenizer *, const LineInfo *,
int tok_str(Tokenizer *, const char *,
int *, const char ***);
#ifdef __cplusplus
}
#endif
#endif /* _HISTEDIT_H_ */

View file

@ -1,4 +1,4 @@
/* $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
@ -32,7 +32,13 @@
* 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
@ -40,7 +46,11 @@
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#ifdef HAVE_VIS_H
#include <vis.h>
#else
#include "np/vis.h"
#endif
#include <sys/stat.h>
static const char hist_cookie[] = "_HiStOrY_V2_\n";
@ -61,6 +71,7 @@ struct history {
history_gfun_t h_prev; /* Get the previous element */
history_gfun_t h_curr; /* Get 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_efun_t h_enter; /* Add an element */
history_efun_t h_add; /* Append to an element */
@ -75,6 +86,7 @@ struct history {
#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 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_malloc(a) malloc(a)
@ -122,16 +134,18 @@ typedef struct history_t {
#define H_UNIQUE 1 /* Store only unique elements */
} 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_first(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_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_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 void history_def_clear(ptr_t, HistEvent *);
private int history_def_insert(history_t *, HistEvent *, const char *);
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)
}
/* 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():
* Delete element hp of the h list
*/
@ -364,6 +396,8 @@ history_def_delete(history_t *h,
HistEventPrivate *evp = (void *)&hp->ev;
if (hp == &h->list)
abort();
if (h->cursor == hp)
h->cursor = hp->prev;
hp->prev->next = hp->next;
hp->next->prev = hp->prev;
h_free((ptr_t) evp->str);
@ -497,6 +531,7 @@ history_init(void)
h->h_clear = history_def_clear;
h->h_enter = history_def_enter;
h->h_add = history_def_add;
h->h_del = history_def_del;
return (h);
}
@ -512,6 +547,8 @@ history_end(History *h)
if (h->h_next == history_def_next)
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)
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_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) {
history_def_init(&h->h_ref, &ev, 0);
h->h_first = history_def_first;
@ -609,6 +646,7 @@ history_set_fun(History *h, History *nh)
h->h_clear = history_def_clear;
h->h_enter = history_def_enter;
h->h_add = history_def_add;
h->h_del = history_def_del;
}
return (-1);
}
@ -625,6 +663,7 @@ history_set_fun(History *h, History *nh)
h->h_clear = nh->h_clear;
h->h_enter = nh->h_enter;
h->h_add = nh->h_add;
h->h_del = nh->h_del;
return (0);
}
@ -676,8 +715,8 @@ history_load(History *h, const char *fname)
(void) strunvis(ptr, line);
line[sz] = c;
if (HENTER(h, &ev, ptr) == -1) {
i = -1;
goto oomem;
i = -1;
goto oomem;
}
}
oomem:
@ -841,6 +880,10 @@ history(History *h, HistEvent *ev, int fun, ...)
retval = HADD(h, ev, str);
break;
case H_DEL:
retval = HDEL(h, ev, va_arg(va, const int));
break;
case H_ENTER:
str = va_arg(va, const char *);
if ((retval = HENTER(h, ev, str)) != -1)
@ -925,6 +968,7 @@ history(History *h, HistEvent *ev, int fun, ...)
hf.h_clear = va_arg(va, history_vfun_t);
hf.h_enter = 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)
he_seterrev(ev, _HE_PARAM_MISSING);

View file

@ -1,4 +1,4 @@
/* $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
@ -32,14 +32,20 @@
* 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
* the extended-key map.
*
* 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)
* to convert these extended-key sequences into input strs
* (XK_STR), editor functions (XK_CMD), or unix commands (XK_EXE).
@ -78,12 +84,12 @@ private int node_trav(EditLine *, key_node_t *, char *,
private int node__try(EditLine *, key_node_t *, const char *,
key_value_t *, int);
private key_node_t *node__get(int);
private void node__free(key_node_t *);
private void node__put(EditLine *, key_node_t *);
private int node__delete(EditLine *, key_node_t **, const char *);
private int node_lookup(EditLine *, const char *, 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
@ -103,7 +109,6 @@ key_init(EditLine *el)
return (0);
}
/* key_end():
* Free the key maps
*/
@ -113,8 +118,7 @@ key_end(EditLine *el)
el_free((ptr_t) el->el_key.buf);
el->el_key.buf = NULL;
/* XXX: provide a function to clear the keys */
el->el_key.map = NULL;
node__free(el->el_key.map);
}
@ -443,7 +447,7 @@ node__put(EditLine *el, key_node_t *ptr)
/* node__get():
* Returns pointer to an key_node_t for ch.
* Returns pointer to a key_node_t for ch.
*/
private key_node_t *
node__get(int ch)
@ -461,7 +465,15 @@ node__get(int ch)
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():
* 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)
/* If match put this char into el->el_key.buf. Recurse */
if (ptr->ch == *str) {
/* 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);
if (ptr->next != NULL)
/* not yet at leaf */
@ -537,7 +549,8 @@ node_enum(EditLine *el, key_node_t *ptr, int cnt)
return (-1);
}
/* 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) {
/* print this key and function */
el->el_key.buf[ncnt + 1] = '"';
@ -568,9 +581,10 @@ key_kprint(EditLine *el, const char *key, key_value_t *val, int ntype)
switch (ntype) {
case XK_STR:
case XK_EXE:
(void) fprintf(el->el_outfile, fmt, key,
key__decode_str(val->str, unparsbuf,
ntype == XK_STR ? "\"\"" : "[]"));
(void) key__decode_str(val->str, unparsbuf,
sizeof(unparsbuf),
ntype == XK_STR ? "\"\"" : "[]");
(void) fprintf(el->el_outfile, fmt, key, unparsbuf);
break;
case XK_CMD:
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)
}
#define ADDC(c) \
if (b < eb) \
*b++ = c; \
else \
b++
/* key__decode_char():
* Put a printable form of char in buf.
*/
private int
key__decode_char(char *buf, int cnt, int ch)
protected int
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) {
buf[cnt++] = '^';
buf[cnt] = '@';
return (cnt);
ADDC('^');
ADDC('@');
return b - sb;
}
if (iscntrl(ch)) {
buf[cnt++] = '^';
ADDC('^');
if (ch == '\177')
buf[cnt] = '?';
ADDC('?');
else
buf[cnt] = ch | 0100;
ADDC(ch | 0100);
} else if (ch == '^') {
buf[cnt++] = '\\';
buf[cnt] = '^';
ADDC('\\');
ADDC('^');
} else if (ch == '\\') {
buf[cnt++] = '\\';
buf[cnt] = '\\';
ADDC('\\');
ADDC('\\');
} else if (ch == ' ' || (el_isprint(ch) && !isspace(ch))) {
buf[cnt] = ch;
ADDC(ch);
} else {
buf[cnt++] = '\\';
buf[cnt++] = (((unsigned int) ch >> 6) & 7) + '0';
buf[cnt++] = (((unsigned int) ch >> 3) & 7) + '0';
buf[cnt] = (ch & 7) + '0';
ADDC('\\');
ADDC((((unsigned int) ch >> 6) & 7) + '0');
ADDC((((unsigned int) ch >> 3) & 7) + '0');
ADDC((ch & 7) + '0');
}
return (cnt);
return b - sb;
}
/* key__decode_str():
* Make a printable version of the ey
*/
protected char *
key__decode_str(const char *str, char *buf, const char *sep)
protected int
key__decode_str(const char *str, char *buf, int len, const char *sep)
{
char *b;
char *b = buf, *eb = b + len;
const char *p;
b = buf;
if (sep[0] != '\0')
*b++ = sep[0];
if (*str == 0) {
*b++ = '^';
*b++ = '@';
if (sep[0] != '\0' && sep[1] != '\0')
*b++ = sep[1];
*b++ = 0;
return (buf);
if (sep[0] != '\0') {
ADDC(sep[0]);
}
if (*str == '\0') {
ADDC('^');
ADDC('@');
if (sep[0] != '\0' && sep[1] != '\0') {
ADDC(sep[1]);
}
goto done;
}
for (p = str; *p != 0; p++) {
if (iscntrl((unsigned char) *p)) {
*b++ = '^';
if (*p == '\177')
*b++ = '?';
else
*b++ = *p | 0100;
ADDC('^');
if (*p == '\177') {
ADDC('?');
} else {
ADDC(*p | 0100);
}
} else if (*p == '^' || *p == '\\') {
*b++ = '\\';
*b++ = *p;
ADDC('\\');
ADDC(*p);
} else if (*p == ' ' || (el_isprint((unsigned char) *p) &&
!isspace((unsigned char) *p))) {
*b++ = *p;
ADDC(*p);
} else {
*b++ = '\\';
*b++ = (((unsigned int) *p >> 6) & 7) + '0';
*b++ = (((unsigned int) *p >> 3) & 7) + '0';
*b++ = (*p & 7) + '0';
ADDC('\\');
ADDC((((unsigned int) *p >> 6) & 7) + '0');
ADDC((((unsigned int) *p >> 3) & 7) + '0');
ADDC((*p & 7) + '0');
}
}
if (sep[0] != '\0' && sep[1] != '\0')
*b++ = sep[1];
*b++ = 0;
return (buf); /* should check for overflow */
if (sep[0] != '\0' && sep[1] != '\0') {
ADDC(sep[1]);
}
done:
ADDC('\0');
if (b - buf >= len)
buf[len - 1] = '\0';
return b - buf;
}

View file

@ -1,4 +1,4 @@
/* $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
@ -74,6 +74,8 @@ protected int key_delete(EditLine *, const char *);
protected void key_print(EditLine *, const char *);
protected void key_kprint(EditLine *, const char *, key_value_t *,
int);
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 */

View file

@ -1,124 +0,0 @@
/* $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 */

View file

@ -1,5 +1,5 @@
#!/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
# The Regents of the University of California. All rights reserved.
@ -15,11 +15,7 @@
# 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
# 3. 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.
#
@ -68,6 +64,7 @@ case $FLAG in
/\(\):/ {
pr = substr($2, 1, 2);
if (pr == "vi" || pr == "em" || pr == "ed") {
# XXXMYSQL: support CRLF
name = substr($2, 1, index($2,"(") - 1);
#
# XXX: need a space between name and prototype so that -fc and -fh
@ -87,7 +84,7 @@ case $FLAG in
cat $FILES | $AWK '
BEGIN {
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");
low = "abcdefghijklmnopqrstuvwxyz_";
high = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_";
@ -97,6 +94,7 @@ case $FLAG in
/\(\):/ {
pr = substr($2, 1, 2);
if (pr == "vi" || pr == "em" || pr == "ed") {
# XXXMYSQL: support CRLF
name = substr($2, 1, index($2,"(") - 1);
uname = "";
fname = "";
@ -117,13 +115,13 @@ case $FLAG in
printf(" \"");
for (i = 2; i < NF; i++)
printf("%s ", $i);
sub("\r", "", $i);
# XXXMYSQL: support CRLF
sub("\r", "", $i);
printf("%s\" },\n", $i);
ok = 0;
}
}
END {
printf(" { NULL, 0, NULL }\n");
printf("};\n");
printf("\nprotected const el_bindings_t* help__get()");
printf("{ return el_func_help; }\n");
@ -144,6 +142,7 @@ case $FLAG in
# generate fcns.h from various .h files
#
# XXXMYSQL: use portable tr syntax
-fh)
cat $FILES | $AWK '/el_action_t/ { print $3 }' | \
sort | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ | $AWK '
@ -170,7 +169,7 @@ case $FLAG in
cat $FILES | $AWK '/el_action_t/ { print $3 }' | sort | $AWK '
BEGIN {
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[] = {");
maxlen = 80;
needn = 1;
@ -220,6 +219,7 @@ case $FLAG in
/\(\):/ {
pr = substr($2, 1, 2);
if (pr == "vi" || pr == "em" || pr == "ed") {
# XXXMYSQL: support CRLF
name = substr($2, 1, index($2, "(") - 1);
fname = "";
for (i = 1; i <= length(name); i++) {

View file

@ -1,4 +1,4 @@
/* $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
@ -32,7 +32,13 @@
* 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
@ -1118,11 +1124,12 @@ private void
map_print_key(EditLine *el, el_action_t *map, const char *in)
{
char outbuf[EL_BUFSIZ];
el_bindings_t *bp;
el_bindings_t *bp, *ep;
if (in[0] == '\0' || in[1] == '\0') {
(void) key__decode_str(in, outbuf, "");
for (bp = el->el_map.help; bp->name != NULL; bp++)
(void) key__decode_str(in, outbuf, sizeof(outbuf), "");
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]) {
(void) fprintf(el->el_outfile,
"%s\t->\t%s\n", outbuf, bp->name);
@ -1139,7 +1146,7 @@ map_print_key(EditLine *el, el_action_t *map, const char *in)
private void
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 unparsbuf[EL_BUFSIZ], extrabuf[EL_BUFSIZ];
@ -1148,39 +1155,47 @@ map_print_some_keys(EditLine *el, el_action_t *map, int first, int last)
lastbuf[0] = last;
lastbuf[1] = 0;
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,
"%-15s-> is undefined\n",
key__decode_str(firstbuf, unparsbuf, STRQQ));
"%-15s-> is undefined\n", unparsbuf);
}
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 (first == last) {
(void) key__decode_str(firstbuf, unparsbuf,
sizeof(unparsbuf), STRQQ);
(void) fprintf(el->el_outfile, "%-15s-> %s\n",
key__decode_str(firstbuf, unparsbuf, STRQQ),
bp->name);
unparsbuf, bp->name);
} else {
(void) key__decode_str(firstbuf, unparsbuf,
sizeof(unparsbuf), STRQQ);
(void) key__decode_str(lastbuf, extrabuf,
sizeof(extrabuf), STRQQ);
(void) fprintf(el->el_outfile,
"%-4s to %-7s-> %s\n",
key__decode_str(firstbuf, unparsbuf, STRQQ),
key__decode_str(lastbuf, extrabuf, STRQQ),
bp->name);
unparsbuf, extrabuf, bp->name);
}
return;
}
}
#ifdef MAP_DEBUG
if (map == el->el_map.key) {
(void) key__decode_str(firstbuf, unparsbuf,
sizeof(unparsbuf), STRQQ);
(void) fprintf(el->el_outfile,
"BUG!!! %s isn't bound to anything.\n",
key__decode_str(firstbuf, unparsbuf, STRQQ));
"BUG!!! %s isn't bound to anything.\n", unparsbuf);
(void) fprintf(el->el_outfile, "el->el_map.key[%d] == %d\n",
first, el->el_map.key[first]);
} else {
(void) key__decode_str(firstbuf, unparsbuf,
sizeof(unparsbuf), STRQQ);
(void) fprintf(el->el_outfile,
"BUG!!! %s isn't bound to anything.\n",
key__decode_str(firstbuf, unparsbuf, STRQQ));
"BUG!!! %s isn't bound to anything.\n", unparsbuf);
(void) fprintf(el->el_outfile, "el->el_map.alt[%d] == %d\n",
first, el->el_map.alt[first]);
}
@ -1237,7 +1252,7 @@ map_bind(EditLine *el, int argc, const char **argv)
char outbuf[EL_BUFSIZ];
const char *in = NULL;
char *out = NULL;
el_bindings_t *bp;
el_bindings_t *bp, *ep;
int cmd;
int key;
@ -1279,8 +1294,8 @@ map_bind(EditLine *el, int argc, const char **argv)
return (0);
case 'l':
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++)
(void) fprintf(el->el_outfile,
"%s\n\t%s\n",
bp->name, bp->description);
@ -1367,7 +1382,7 @@ map_bind(EditLine *el, int argc, const char **argv)
break;
default:
EL_ABORT((el->el_errfile, "Bad XK_ type\n", ntype));
EL_ABORT((el->el_errfile, "Bad XK_ type %d\n", ntype));
break;
}
return (0);
@ -1381,7 +1396,7 @@ protected int
map_addfunc(EditLine *el, const char *name, const char *help, el_func_t func)
{
void *p;
int nf = el->el_map.nfunc + 2;
int nf = el->el_map.nfunc + 1;
if (name == NULL || help == NULL || func == NULL)
return (-1);
@ -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].func = nf;
el->el_map.help[nf].description = help;
el->el_map.help[++nf].name = NULL;
el->el_map.nfunc++;
return (0);

View file

@ -1,4 +1,4 @@
/* $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.
@ -15,13 +15,6 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
@ -36,17 +29,24 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#else
#include "config.h"
#include <stdio.h>
#endif
#if !HAVE_FGETLN
#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 <errno.h>
#include <string.h>
#endif
char *
fgetln(fp, len)
FILE *fp;
size_t *len;
fgetln(FILE *fp, size_t *len)
{
static char *buf = NULL;
static size_t bufsiz = 0;
@ -61,8 +61,8 @@ fgetln(fp, len)
if (fgets(buf, bufsiz, fp) == NULL)
return NULL;
*len = 0;
*len = 0;
while ((ptr = strchr(&buf[*len], '\n')) == NULL) {
size_t nbufsiz = bufsiz + BUFSIZ;
char *nbuf = realloc(buf, nbufsiz);
@ -76,13 +76,33 @@ fgetln(fp, len)
} else
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;
}
*len = bufsiz;
bufsiz = nbufsiz;
}
*len = (ptr - buf) + 1;
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

View file

@ -1,59 +1,68 @@
/* $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>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THIS SOFTWARE IS PROVIDED ``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 AUTHOR 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.
* THE SOFTWARE IS PROVIDED "AS IS" AND TODD C. MILLER DISCLAIMS ALL
* WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL TODD C. MILLER BE LIABLE
* FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#if !defined(_KERNEL) && !defined(_STANDALONE)
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#else
#include "config.h"
#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 */
#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
#if defined(LIBC_SCCS) && !defined(lint)
#endif /* LIBC_SCCS and not lint */
#ifdef _LIBC
#include "namespace.h"
#endif
#include <sys/types.h>
#include <assert.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
* full size of dst, not space left). At most siz-1 characters
* will be copied. Always NUL terminates (unless siz <= strlen(dst)).
* Returns strlen(initial dst) + strlen(src); if retval >= siz,
* truncation occurred.
* Returns strlen(src) + MIN(siz, strlen(initial dst)).
* If retval >= siz, truncation occurred.
*/
size_t strlcat(dst, src, siz)
char *dst;
const char *src;
size_t siz;
size_t
strlcat(char *dst, const char *src, size_t siz)
{
register char *d = dst;
register const char *s = src;
register size_t n = siz;
char *d = dst;
const char *s = src;
size_t n = siz;
size_t dlen;
_DIAGASSERT(dst != NULL);
_DIAGASSERT(src != NULL);
/* Find the end of dst and adjust bytes left but don't go past end */
while (n-- != 0 && *d != '\0')
d++;
@ -73,3 +82,4 @@ size_t strlcat(dst, src, siz)
return(dlen + (s - src)); /* count does not include NUL */
}
#endif

View file

@ -1,59 +1,63 @@
/* $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>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THIS SOFTWARE IS PROVIDED ``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 AUTHOR 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.
* THE SOFTWARE IS PROVIDED "AS IS" AND TODD C. MILLER DISCLAIMS ALL
* WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL TODD C. MILLER BE LIABLE
* FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#if !defined(_KERNEL) && !defined(_STANDALONE)
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#else
#include "config.h"
#endif
#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 /* 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 <assert.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
* will be copied. Always NUL terminates (unless siz == 0).
* Returns strlen(src); if retval >= siz, truncation occurred.
*/
size_t strlcpy(dst, src, siz)
char *dst;
const char *src;
size_t siz;
size_t
strlcpy(char *dst, const char *src, size_t siz)
{
register char *d = dst;
register const char *s = src;
register size_t n = siz;
char *d = dst;
const char *s = src;
size_t n = siz;
_DIAGASSERT(dst != NULL);
_DIAGASSERT(src != NULL);
/* Copy as many bytes as will fit */
if (n != 0 && --n != 0) {
@ -73,3 +77,4 @@ size_t strlcpy(dst, src, siz)
return(s - src - 1); /* count does not include NUL */
}
#endif

View file

@ -1,4 +1,4 @@
/* $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
@ -12,11 +12,7 @@
* 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
* 3. 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.
*
@ -34,34 +30,30 @@
*/
#include "config.h"
#if defined(LIBC_SCCS) && !defined(lint)
#if 0
static char sccsid[] = "@(#)unvis.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: unvis.c,v 1.22 2002/03/23 17:38:27 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
#define __LIBC12_SOURCE__
#include <sys/types.h>
#include <assert.h>
#include <ctype.h>
#include <stdio.h>
#ifdef HAVE_VIS_H
#include <vis.h>
#else
#include "np/vis.h"
#endif
#ifdef __weak_alias
__weak_alias(strunvis,_strunvis)
__weak_alias(unvis,_unvis)
#endif
#ifdef __warn_references
__warn_references(unvis,
"warning: reference to compatibility unvis(); include <vis.h> for correct reference")
#endif
#if !HAVE_VIS_H
#if !HAVE_VIS
/*
* decode driven by state machine
*/
@ -72,30 +64,22 @@ __warn_references(unvis,
#define S_CTRL 4 /* control char started (^) */
#define S_OCTAL2 5 /* octal digit 2 */
#define S_OCTAL3 6 /* octal digit 3 */
#define S_HEX1 7 /* hex digit */
#define S_HEX2 8 /* hex digit 2 */
#define S_HEX1 7 /* hex digit */
#define S_HEX2 8 /* hex digit 2 */
#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7')
#define xtod(c) (isdigit(c) ? (c - '0') : ((tolower(c) - 'a') + 10))
/*
* unvis - decode characters previously encoded by vis
*/
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
*/
int
__unvis13(cp, c, astate, flag)
char *cp;
int c;
int *astate, flag;
{
unsigned char uc = (unsigned char)c;
_DIAGASSERT(cp != NULL);
_DIAGASSERT(astate != NULL);
@ -105,7 +89,7 @@ __unvis13(cp, c, astate, flag)
|| *astate == S_HEX2) {
*astate = S_GROUND;
return (UNVIS_VALID);
}
}
return (*astate == S_GROUND ? UNVIS_NOCHAR : UNVIS_SYNBAD);
}
@ -116,7 +100,7 @@ __unvis13(cp, c, astate, flag)
if (c == '\\') {
*astate = S_START;
return (0);
}
}
if ((flag & VIS_HTTPSTYLE) && c == '%') {
*astate = S_HEX1;
return (0);
@ -193,7 +177,7 @@ __unvis13(cp, c, astate, flag)
}
*astate = S_GROUND;
return (UNVIS_SYNBAD);
case S_META:
if (c == '-')
*astate = S_META1;
@ -204,12 +188,12 @@ __unvis13(cp, c, astate, flag)
return (UNVIS_SYNBAD);
}
return (0);
case S_META1:
*astate = S_GROUND;
*cp |= c;
return (UNVIS_VALID);
case S_CTRL:
if (c == '?')
*cp |= 0177;
@ -219,23 +203,23 @@ __unvis13(cp, c, astate, flag)
return (UNVIS_VALID);
case S_OCTAL2: /* second possible octal digit */
if (isoctal(c)) {
/*
* yes - and maybe a third
if (isoctal(uc)) {
/*
* yes - and maybe a third
*/
*cp = (*cp << 3) + (c - '0');
*astate = S_OCTAL3;
*astate = S_OCTAL3;
return (0);
}
/*
* no - done with current sequence, push back passed char
}
/*
* no - done with current sequence, push back passed char
*/
*astate = S_GROUND;
return (UNVIS_VALIDPUSH);
case S_OCTAL3: /* third possible octal digit */
*astate = S_GROUND;
if (isoctal(c)) {
if (isoctal(uc)) {
*cp = (*cp << 3) + (c - '0');
return (UNVIS_VALID);
}
@ -243,27 +227,30 @@ __unvis13(cp, c, astate, flag)
* we were done, push back passed char
*/
return (UNVIS_VALIDPUSH);
case S_HEX1:
if (isxdigit(c)) {
*cp = xtod(c);
if (isxdigit(uc)) {
*cp = xtod(uc);
*astate = S_HEX2;
return (0);
}
/*
* no - done with current sequence, push back passed char
/*
* no - done with current sequence, push back passed char
*/
*astate = S_GROUND;
return (UNVIS_VALIDPUSH);
case S_HEX2:
*astate = S_GROUND;
if (isxdigit(c)) {
*cp = xtod(c) | (*cp << 4);
*astate = S_GROUND;
if (isxdigit(uc)) {
*cp = xtod(uc) | (*cp << 4);
return (UNVIS_VALID);
}
return (UNVIS_VALIDPUSH);
default:
/*
* decoder in unknown state - (probably uninitialized)
return (UNVIS_VALIDPUSH);
default:
/*
* decoder in unknown state - (probably uninitialized)
*/
*astate = S_GROUND;
return (UNVIS_SYNBAD);
@ -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.
* Dst is null terminated.
@ -291,8 +278,8 @@ strunvisx(dst, src, flag)
_DIAGASSERT(dst != NULL);
while ((c = *src++) != '\0') {
again:
switch (__unvis13(dst, c, &state, flag)) {
again:
switch (unvis(dst, c, &state, flag)) {
case UNVIS_VALID:
dst++;
break;
@ -306,7 +293,7 @@ strunvisx(dst, src, flag)
return (-1);
}
}
if (__unvis13(dst, c, &state, UNVIS_END) == UNVIS_VALID)
if (unvis(dst, c, &state, UNVIS_END) == UNVIS_VALID)
dst++;
*dst = '\0';
return (dst - start);

View file

@ -1,7 +1,6 @@
/* $NetBSD: vis.c,v 1.22 2002/03/23 17:38:27 christos Exp $ */
/* $NetBSD: vis.c,v 1.38 2008/09/04 09:41:44 lukem Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
@ -13,11 +12,7 @@
* 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
* 3. 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.
*
@ -34,21 +29,47 @@
* SUCH DAMAGE.
*/
/*-
* Copyright (c) 1999, 2005 The NetBSD Foundation, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: vis.c,v 1.22 2002/03/23 17:38:27 christos Exp $");
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
#include <assert.h>
#ifdef HAVE_ALLOCA_H
#include <alloca.h>
#ifdef HAVE_VIS_H
#include <vis.h>
#else
#include "np/vis.h"
#endif
#include <stdlib.h>
#include "np/vis.h"
#ifdef __weak_alias
__weak_alias(strsvis,_strsvis)
__weak_alias(strsvisx,_strsvisx)
@ -58,63 +79,61 @@ __weak_alias(svis,_svis)
__weak_alias(vis,_vis)
#endif
#if !HAVE_VIS_H
#if !HAVE_VIS || !HAVE_SVIS
#include <ctype.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#undef BELL
#if defined(__STDC__)
#define BELL '\a'
#else
#define BELL '\007'
#endif
#define isoctal(c) (((unsigned char)(c)) >= '0' && ((unsigned char)(c)) <= '7')
static char *do_svis(char *, int, int, int, const char *);
#undef BELL
#define BELL '\a'
#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7')
#define iswhite(c) (c == ' ' || c == '\t' || c == '\n')
#define issafe(c) (c == '\b' || c == BELL || c == '\r')
#define xtoa(c) "0123456789abcdef"[c]
#define MAXEXTRAS 5
#define MAXEXTRAS 5
#define MAKEEXTRALIST(flag, extra, orig_str) \
do { \
const char *orig = orig_str; \
const char *o = orig; \
char *e; \
while (*o++) \
continue; \
extra = malloc((size_t)((o - orig) + MAXEXTRAS)); \
if (!extra) break; \
for (o = orig, e = extra; (*e++ = *o++) != '\0';) \
continue; \
e--; \
if (flag & VIS_SP) *e++ = ' '; \
if (flag & VIS_TAB) *e++ = '\t'; \
if (flag & VIS_NL) *e++ = '\n'; \
if ((flag & VIS_NOSLASH) == 0) *e++ = '\\'; \
*e = '\0'; \
} while (/*CONSTCOND*/0)
char *MAKEEXTRALIST(unsigned int flag, const char *orig)
{
const char *o = orig;
char *e, *extra;
while (*o++)
continue;
extra = (char*) malloc((size_t)((o - orig) + MAXEXTRAS));
assert(extra);
for (o = orig, e = extra; (*e++ = *o++) != '\0';)
continue;
e--;
if (flag & VIS_SP) *e++ = ' ';
if (flag & VIS_TAB) *e++ = '\t';
if (flag & VIS_NL) *e++ = '\n';
if ((flag & VIS_NOSLASH) == 0) *e++ = '\\';
*e = '\0';
return extra;
/*
* This is do_hvis, for HTTP style (RFC 1808)
*/
static char *
do_hvis(char *dst, int c, int flag, int nextc, const char *extra)
{
if (!isascii(c) || !isalnum(c) || strchr("$-_.+!*'(),", c) != NULL) {
*dst++ = '%';
*dst++ = xtoa(((unsigned int)c >> 4) & 0xf);
*dst++ = xtoa((unsigned int)c & 0xf);
} else {
dst = do_svis(dst, c, flag, nextc, extra);
}
return dst;
}
/*
* This is HVIS, the macro of vis used to HTTP style (RFC 1808)
*/
#define HVIS(dst, c, flag, nextc, extra) \
do \
if (!isascii(c) || !isalnum(c) || strchr("$-_.+!*'(),", c) != NULL) { \
*dst++ = '%'; \
*dst++ = xtoa(((unsigned int)c >> 4) & 0xf); \
*dst++ = xtoa((unsigned int)c & 0xf); \
} else { \
SVIS(dst, c, flag, nextc, extra); \
} \
while (/*CONSTCOND*/0)
/*
* This is SVIS, the central macro of vis.
* This is do_vis, the central code of vis.
* dst: Pointer to the destination buffer
* c: Character to encode
* flag: Flag word
@ -122,95 +141,103 @@ while (/*CONSTCOND*/0)
* extra: Pointer to the list of extra characters to be
* backslash-protected.
*/
#define SVIS(dst, c, flag, nextc, extra) \
do { \
int isextra, isc; \
isextra = strchr(extra, c) != NULL; \
if (!isextra && isascii(c) && (isgraph(c) || iswhite(c) || \
((flag & VIS_SAFE) && issafe(c)))) { \
*dst++ = c; \
break; \
} \
isc = 0; \
if (flag & VIS_CSTYLE) { \
switch (c) { \
case '\n': \
isc = 1; *dst++ = '\\'; *dst++ = 'n'; \
break; \
case '\r': \
isc = 1; *dst++ = '\\'; *dst++ = 'r'; \
break; \
case '\b': \
isc = 1; *dst++ = '\\'; *dst++ = 'b'; \
break; \
case BELL: \
isc = 1; *dst++ = '\\'; *dst++ = 'a'; \
break; \
case '\v': \
isc = 1; *dst++ = '\\'; *dst++ = 'v'; \
break; \
case '\t': \
isc = 1; *dst++ = '\\'; *dst++ = 't'; \
break; \
case '\f': \
isc = 1; *dst++ = '\\'; *dst++ = 'f'; \
break; \
case ' ': \
isc = 1; *dst++ = '\\'; *dst++ = 's'; \
break; \
case '\0': \
isc = 1; *dst++ = '\\'; *dst++ = '0'; \
if (isoctal(nextc)) { \
*dst++ = '0'; \
*dst++ = '0'; \
} \
} \
} \
if (isc) break; \
if (isextra || ((c & 0177) == ' ') || (flag & VIS_OCTAL)) { \
*dst++ = '\\'; \
*dst++ = (unsigned char)(((unsigned int)(unsigned char)c >> 6) & 03) + '0'; \
*dst++ = (unsigned char)(((unsigned int)(unsigned char)c >> 3) & 07) + '0'; \
*dst++ = (c & 07) + '0'; \
} else { \
if ((flag & VIS_NOSLASH) == 0) *dst++ = '\\'; \
if (c & 0200) { \
c &= 0177; *dst++ = 'M'; \
} \
if (iscntrl(c)) { \
*dst++ = '^'; \
if (c == 0177) \
*dst++ = '?'; \
else \
*dst++ = c + '@'; \
} else { \
*dst++ = '-'; *dst++ = c; \
} \
} \
} while (/*CONSTCOND*/0)
static char *
do_svis(char *dst, int c, int flag, int nextc, const char *extra)
{
int isextra;
isextra = strchr(extra, c) != NULL;
if (!isextra && isascii(c) && (isgraph(c) || iswhite(c) ||
((flag & VIS_SAFE) && issafe(c)))) {
*dst++ = c;
return dst;
}
if (flag & VIS_CSTYLE) {
switch (c) {
case '\n':
*dst++ = '\\'; *dst++ = 'n';
return dst;
case '\r':
*dst++ = '\\'; *dst++ = 'r';
return dst;
case '\b':
*dst++ = '\\'; *dst++ = 'b';
return dst;
case BELL:
*dst++ = '\\'; *dst++ = 'a';
return dst;
case '\v':
*dst++ = '\\'; *dst++ = 'v';
return dst;
case '\t':
*dst++ = '\\'; *dst++ = 't';
return dst;
case '\f':
*dst++ = '\\'; *dst++ = 'f';
return dst;
case ' ':
*dst++ = '\\'; *dst++ = 's';
return dst;
case '\0':
*dst++ = '\\'; *dst++ = '0';
if (isoctal(nextc)) {
*dst++ = '0';
*dst++ = '0';
}
return dst;
default:
if (isgraph(c)) {
*dst++ = '\\'; *dst++ = c;
return dst;
}
}
}
if (isextra || ((c & 0177) == ' ') || (flag & VIS_OCTAL)) {
*dst++ = '\\';
*dst++ = (u_char)(((u_int32_t)(u_char)c >> 6) & 03) + '0';
*dst++ = (u_char)(((u_int32_t)(u_char)c >> 3) & 07) + '0';
*dst++ = (c & 07) + '0';
} else {
if ((flag & VIS_NOSLASH) == 0) *dst++ = '\\';
if (c & 0200) {
c &= 0177; *dst++ = 'M';
}
if (iscntrl(c)) {
*dst++ = '^';
if (c == 0177)
*dst++ = '?';
else
*dst++ = c + '@';
} else {
*dst++ = '-'; *dst++ = c;
}
}
return dst;
}
/*
* svis - visually encode characters, also encoding the characters
* pointed to by `extra'
* pointed to by `extra'
*/
char *
svis(dst, c, flag, nextc, extra)
char *dst;
int c, flag, nextc;
const char *extra;
svis(char *dst, int c, int flag, int nextc, const char *extra)
{
char *nextra, *to_be_freed;
char *nextra = NULL;
_DIAGASSERT(dst != NULL);
_DIAGASSERT(extra != NULL);
nextra= to_be_freed= MAKEEXTRALIST(flag, extra);
MAKEEXTRALIST(flag, nextra, extra);
if (!nextra) {
*dst = '\0'; /* can't create nextra, return "" */
return dst;
}
if (flag & VIS_HTTPSTYLE)
HVIS(dst, c, flag, nextc, nextra);
dst = do_hvis(dst, c, flag, nextc, nextra);
else
SVIS(dst, c, flag, nextc, nextra);
dst = do_svis(dst, c, flag, nextc, nextra);
free(nextra);
*dst = '\0';
free(to_be_freed);
return(dst);
return dst;
}
@ -221,140 +248,146 @@ svis(dst, c, flag, nextc, extra)
* be encoded, too. These functions are useful e. g. to
* encode strings in such a way so that they are not interpreted
* by a shell.
*
*
* Dst must be 4 times the size of src to account for possible
* expansion. The length of dst, not including the trailing NULL,
* is returned.
* is returned.
*
* Strsvisx encodes exactly len bytes from src into dst.
* This is useful for encoding a block of data.
*/
int
strsvis(dst, src, flag, extra)
char *dst;
const char *src;
int flag;
const char *extra;
strsvis(char *dst, const char *csrc, int flag, const char *extra)
{
char c;
int c;
char *start;
char *nextra, *to_be_freed;
char *nextra = NULL;
const unsigned char *src = (const unsigned char *)csrc;
_DIAGASSERT(dst != NULL);
_DIAGASSERT(src != NULL);
_DIAGASSERT(extra != NULL);
nextra= to_be_freed= MAKEEXTRALIST(flag, extra);
MAKEEXTRALIST(flag, nextra, extra);
if (!nextra) {
*dst = '\0'; /* can't create nextra, return "" */
return 0;
}
if (flag & VIS_HTTPSTYLE) {
for (start = dst; (c = *src++) != '\0'; /* empty */)
HVIS(dst, c, flag, *src, nextra);
dst = do_hvis(dst, c, flag, *src, nextra);
} else {
for (start = dst; (c = *src++) != '\0'; /* empty */)
SVIS(dst, c, flag, *src, nextra);
dst = do_svis(dst, c, flag, *src, nextra);
}
free(nextra);
*dst = '\0';
free(to_be_freed);
return (dst - start);
}
int
strsvisx(dst, src, len, flag, extra)
char *dst;
const char *src;
size_t len;
int flag;
const char *extra;
strsvisx(char *dst, const char *csrc, size_t len, int flag, const char *extra)
{
char c;
unsigned char c;
char *start;
char *nextra, *to_be_freed;
char *nextra = NULL;
const unsigned char *src = (const unsigned char *)csrc;
_DIAGASSERT(dst != NULL);
_DIAGASSERT(src != NULL);
_DIAGASSERT(extra != NULL);
nextra= to_be_freed= MAKEEXTRALIST(flag, extra);
MAKEEXTRALIST(flag, nextra, extra);
if (! nextra) {
*dst = '\0'; /* can't create nextra, return "" */
return 0;
}
if (flag & VIS_HTTPSTYLE) {
for (start = dst; len > 0; len--) {
c = *src++;
HVIS(dst, c, flag, len ? *src : '\0', nextra);
dst = do_hvis(dst, c, flag,
len > 1 ? *src : '\0', nextra);
}
} else {
for (start = dst; len > 0; len--) {
c = *src++;
SVIS(dst, c, flag, len ? *src : '\0', nextra);
dst = do_svis(dst, c, flag,
len > 1 ? *src : '\0', nextra);
}
}
free(nextra);
*dst = '\0';
free(to_be_freed);
return (dst - start);
}
#endif
#if !HAVE_VIS
/*
* vis - visually encode characters
*/
char *
vis(dst, c, flag, nextc)
char *dst;
int c, flag, nextc;
vis(char *dst, int c, int flag, int nextc)
{
char *extra, *to_be_freed;
char *extra = NULL;
unsigned char uc = (unsigned char)c;
_DIAGASSERT(dst != NULL);
extra= to_be_freed= MAKEEXTRALIST(flag, "");
MAKEEXTRALIST(flag, extra, "");
if (! extra) {
*dst = '\0'; /* can't create extra, return "" */
return dst;
}
if (flag & VIS_HTTPSTYLE)
HVIS(dst, c, flag, nextc, extra);
dst = do_hvis(dst, uc, flag, nextc, extra);
else
SVIS(dst, c, flag, nextc, extra);
dst = do_svis(dst, uc, flag, nextc, extra);
free(extra);
*dst = '\0';
free(to_be_freed);
return (dst);
return dst;
}
/*
* strvis, strvisx - visually encode characters from src into dst
*
*
* Dst must be 4 times the size of src to account for possible
* expansion. The length of dst, not including the trailing NULL,
* is returned.
* is returned.
*
* Strvisx encodes exactly len bytes from src into dst.
* This is useful for encoding a block of data.
*/
int
strvis(dst, src, flag)
char *dst;
const char *src;
int flag;
strvis(char *dst, const char *src, int flag)
{
char *extra;
int tmp;
char *extra = NULL;
int rv;
extra= MAKEEXTRALIST(flag, "");
tmp= strsvis(dst, src, flag, extra);
MAKEEXTRALIST(flag, extra, "");
if (!extra) {
*dst = '\0'; /* can't create extra, return "" */
return 0;
}
rv = strsvis(dst, src, flag, extra);
free(extra);
return tmp;
return rv;
}
int
strvisx(dst, src, len, flag)
char *dst;
const char *src;
size_t len;
int flag;
strvisx(char *dst, const char *src, size_t len, int flag)
{
char *extra;
int tmp;
char *extra = NULL;
int rv;
extra= MAKEEXTRALIST(flag, "");
tmp= strsvisx(dst, src, len, flag, extra);
MAKEEXTRALIST(flag, extra, "");
if (!extra) {
*dst = '\0'; /* can't create extra, return "" */
return 0;
}
rv = strsvisx(dst, src, len, flag, extra);
free(extra);
return tmp;
return rv;
}
#endif

View file

@ -1,4 +1,4 @@
/* $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
@ -12,11 +12,7 @@
* 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
* 3. 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.
*
@ -38,9 +34,7 @@
#ifndef _VIS_H_
#define _VIS_H_
#ifdef HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
#endif
#include <sys/types.h>
/*
* to select alternate encoding format
@ -78,6 +72,7 @@
*/
#define UNVIS_END 1 /* no more characters */
__BEGIN_DECLS
char *vis(char *, int, int, int);
char *svis(char *, int, int, int, const char *);
int strvis(char *, const char *, int);
@ -86,11 +81,7 @@ int strvisx(char *, const char *, size_t, int);
int strsvisx(char *, const char *, size_t, int, const char *);
int strunvis(char *, const char *);
int strunvisx(char *, const char *, int);
#ifdef __LIBC12_SOURCE__
int unvis(char *, int, int *, int);
int __unvis13(char *, int, int *, int);
#else
int unvis(char *, int, int *, int) __RENAME(__unvis13);
#endif
__END_DECLS
#endif /* !_VIS_H_ */

View file

@ -1,4 +1,4 @@
/* $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
@ -32,7 +32,13 @@
* 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
@ -129,7 +135,7 @@ el_parse(EditLine *el, int argc, const char *argv[])
* the appropriate character or -1 if the escape is not valid
*/
protected int
parse__escape(const char **const ptr)
parse__escape(const char **ptr)
{
const char *p;
int c;

View file

@ -1,4 +1,4 @@
/* $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
@ -41,7 +41,7 @@
#define _h_el_parse
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 int parse_cmd(EditLine *, const char *);

View file

@ -32,7 +32,13 @@
* 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

View file

@ -1,4 +1,4 @@
/* $NetBSD: read.c,v 1.35 2005/03/09 23:55:02 christos Exp $ */
/* $NetBSD: read.c,v 1.43 2009/02/05 19:15:44 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -32,7 +32,13 @@
* SUCH DAMAGE.
*/
#include <config.h>
#include "config.h"
#if !defined(lint) && !defined(SCCSID)
#if 0
static char sccsid[] = "@(#)read.c 8.1 (Berkeley) 6/4/93";
#else
#endif
#endif /* not lint && not SCCSID */
/*
* read.c: Clean this junk up! This is horrible code.
@ -50,6 +56,7 @@ private int read__fixio(int, int);
private int read_preread(EditLine *);
private int read_char(EditLine *, char *);
private int read_getcmd(EditLine *, el_action_t *, char *);
private void read_pop(c_macro_t *);
/* read_init():
* Initialize the read stuff
@ -205,7 +212,7 @@ read_preread(EditLine *el)
* Push a macro
*/
public void
el_push(EditLine *el, char *str)
el_push(EditLine *el, const char *str)
{
c_macro_t *ma = &el->el_chared.c_macro;
@ -216,7 +223,7 @@ el_push(EditLine *el, char *str)
ma->level--;
}
term_beep(el);
term__flush();
term__flush(el);
}
@ -294,6 +301,19 @@ read_char(EditLine *el, char *cp)
return (num_read);
}
/* read_pop():
* Pop a macro from the stack
*/
private void
read_pop(c_macro_t *ma)
{
int i;
el_free(ma->macro[0]);
for (i = ma->level--; i > 0; i--)
ma->macro[i - 1] = ma->macro[i];
ma->offset = 0;
}
/* el_getc():
* Read a character
@ -304,26 +324,28 @@ el_getc(EditLine *el, char *cp)
int num_read;
c_macro_t *ma = &el->el_chared.c_macro;
term__flush();
term__flush(el);
for (;;) {
if (ma->level < 0) {
if (!read_preread(el))
break;
}
if (ma->level < 0)
break;
if (ma->macro[ma->level][ma->offset] == '\0') {
el_free(ma->macro[ma->level--]);
ma->offset = 0;
if (ma->macro[0][ma->offset] == '\0') {
read_pop(ma);
continue;
}
*cp = ma->macro[ma->level][ma->offset++] & 0377;
if (ma->macro[ma->level][ma->offset] == '\0') {
*cp = ma->macro[0][ma->offset++] & 0377;
if (ma->macro[0][ma->offset] == '\0') {
/* Needed for QuoteMode On */
el_free(ma->macro[ma->level--]);
ma->offset = 0;
read_pop(ma);
}
return (1);
}
@ -357,11 +379,11 @@ read_prepare(EditLine *el)
we have the wrong size. */
el_resize(el);
re_clear_display(el); /* reset the display stuff */
ch_reset(el);
ch_reset(el, 0);
re_refresh(el); /* print the prompt */
if (el->el_flags & UNBUFFERED)
term__flush();
term__flush(el);
}
protected void
@ -438,7 +460,7 @@ el_gets(EditLine *el, int *nread)
else
cp = el->el_line.lastchar;
term__flush();
term__flush(el);
while ((*el->el_read.read_char)(el, cp) == 1) {
/* make sure there is space next character */
@ -478,7 +500,7 @@ el_gets(EditLine *el, int *nread)
#endif /* DEBUG_READ */
break;
}
if ((unsigned int)cmdnum >= el->el_map.nfunc) { /* BUG CHECK command */
if ((unsigned int)cmdnum >= (unsigned int)el->el_map.nfunc) { /* BUG CHECK command */
#ifdef DEBUG_EDIT
(void) fprintf(el->el_errfile,
"ERROR: illegal command from key 0%o\r\n", ch);
@ -570,7 +592,7 @@ el_gets(EditLine *el, int *nread)
#endif /* DEBUG_READ */
/* put (real) cursor in a known place */
re_clear_display(el); /* reset the display stuff */
ch_reset(el); /* reset the input pointers */
ch_reset(el, 1); /* reset the input pointers */
re_refresh(el); /* print the prompt again */
break;
@ -581,7 +603,7 @@ el_gets(EditLine *el, int *nread)
"*** editor ERROR ***\r\n\n");
#endif /* DEBUG_READ */
term_beep(el);
term__flush();
term__flush(el);
break;
}
el->el_state.argument = 1;
@ -591,7 +613,7 @@ el_gets(EditLine *el, int *nread)
break;
}
term__flush(); /* flush any buffered output */
term__flush(el); /* flush any buffered output */
/* make sure the tty is set up correctly */
if ((el->el_flags & UNBUFFERED) == 0) {
read_finish(el);

View file

@ -1,4 +1,4 @@
/* $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.
@ -15,13 +15,6 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,4 @@
/* $NetBSD: readline.h,v 1.12 2004/09/08 18:15:37 christos Exp $ */
/* $NetBSD: readline.h,v 1.24 2009/02/05 19:15:26 christos Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@ -15,13 +15,6 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
@ -45,14 +38,14 @@
/* typedefs */
typedef int Function(const char *, int);
typedef void VFunction(void);
typedef void VCPFunction(char *);
typedef char *CPFunction(const char *, int);
typedef char **CPPFunction(const char *, int, int);
typedef void *histdata_t;
typedef char *rl_compentry_func_t(const char *, int);
typedef struct _hist_entry {
const char *line;
histdata_t *data;
const char *data;
} HIST_ENTRY;
typedef struct _keymap_entry {
@ -73,7 +66,7 @@ typedef KEYMAP_ENTRY *Keymap;
#ifndef CTRL
#include <sys/ioctl.h>
#if defined(__GLIBC__) || defined(__MWERKS__)
#if !defined(__sun__) && !defined(__hpux__)
#include <sys/ttydefaults.h>
#endif
#ifndef CTRL
@ -102,8 +95,9 @@ extern int max_input_history;
extern char *rl_basic_word_break_characters;
extern char *rl_completer_word_break_characters;
extern char *rl_completer_quote_characters;
extern CPFunction *rl_completion_entry_function;
extern Function *rl_completion_entry_function;
extern CPPFunction *rl_attempted_completion_function;
extern int rl_attempted_completion_over;
extern int rl_completion_type;
extern int rl_completion_query_items;
extern char *rl_special_prefixes;
@ -122,11 +116,13 @@ extern KEYMAP_ENTRY_ARRAY emacs_standard_keymap,
emacs_ctlx_keymap;
extern int rl_filename_completion_desired;
extern int rl_ignore_completion_duplicates;
extern Function *rl_getc_function;
extern int (*rl_getc_function)(FILE *);
extern VFunction *rl_redisplay_function;
extern VFunction *rl_completion_display_matches_hook;
extern VFunction *rl_prep_term_function;
extern VFunction *rl_deprep_term_function;
extern int readline_echoing_p;
extern int _rl_print_completions_horizontally;
/* supported functions */
char *readline(const char *);
@ -141,6 +137,7 @@ int history_is_stifled(void);
int where_history(void);
HIST_ENTRY *current_history(void);
HIST_ENTRY *history_get(int);
HIST_ENTRY *remove_history(int);
int history_total_bytes(void);
int history_set_pos(int);
HIST_ENTRY *previous_history(void);
@ -168,7 +165,7 @@ void rl_reset_terminal(const char *);
int rl_bind_key(int, int (*)(int, int));
int rl_newline(int, int);
void rl_callback_read_char(void);
void rl_callback_handler_install(const char *, VFunction *);
void rl_callback_handler_install(const char *, VCPFunction *);
void rl_callback_handler_remove(void);
void rl_redisplay(void);
int rl_get_previous_history(int, int);
@ -176,13 +173,24 @@ void rl_prep_terminal(int);
void rl_deprep_terminal(void);
int rl_read_init_file(const char *);
int rl_parse_and_bind(const char *);
int rl_variable_bind(const char *, const char *);
void rl_stuff_char(int);
int rl_add_defun(const char *, Function *, int);
void rl_get_screen_size(int *, int *);
void rl_set_screen_size(int, int);
char *rl_filename_completion_function (const char *, int);
int _rl_abort_internal(void);
int _rl_qsort_string_compare(char **, char **);
char **rl_completion_matches(const char *, rl_compentry_func_t *);
void rl_forced_update_display(void);
int rl_set_prompt(const char *);
/*
* The following are not implemented
*/
int rl_kill_text(int, int);
Keymap rl_get_keymap(void);
void rl_set_keymap(Keymap);
Keymap rl_make_bare_keymap(void);
int rl_generic_bind(int, const char *, const char *, Keymap);
int rl_bind_key_in_map(int, Function *, Keymap);

View file

@ -1,4 +1,4 @@
/* $NetBSD: refresh.c,v 1.26 2003/08/07 16:44:33 agc Exp $ */
/* $NetBSD: refresh.c,v 1.28 2008/09/10 15:45:37 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -32,7 +32,13 @@
* SUCH DAMAGE.
*/
#include <config.h>
#include "config.h"
#if !defined(lint) && !defined(SCCSID)
#if 0
static char sccsid[] = "@(#)refresh.c 8.1 (Berkeley) 6/4/93";
#else
#endif
#endif /* not lint && not SCCSID */
/*
* refresh.c: Lower level screen refreshing functions
@ -49,6 +55,7 @@ private void re_update_line(EditLine *, char *, char *, int);
private void re_insert (EditLine *, char *, int, int, char *, int);
private void re_delete(EditLine *, char *, int, int, int);
private void re_fastputc(EditLine *, int);
private void re_clear_eol(EditLine *, int, int, int);
private void re__strncopy(char *, char *, size_t);
private void re__copy_and_pad(char *, const char *, size_t);
@ -315,9 +322,9 @@ re_goto_bottom(EditLine *el)
{
term_move_to_line(el, el->el_refresh.r_oldcv);
term__putc('\n');
term__putc(el, '\n');
re_clear_display(el);
term__flush();
term__flush(el);
}
@ -340,7 +347,7 @@ re_insert(EditLine *el __attribute__((__unused__)),
ELRE_DEBUG(1,
(__F, "re_insert() starting: %d at %d max %d, d == \"%s\"\n",
num, dat, dlen, d));
ELRE_DEBUG(1, (__F, "s == \"%s\"n", s));
ELRE_DEBUG(1, (__F, "s == \"%s\"\n", s));
/* open up the space for num chars */
if (num > 0) {
@ -353,7 +360,7 @@ re_insert(EditLine *el __attribute__((__unused__)),
ELRE_DEBUG(1, (__F,
"re_insert() after insert: %d at %d max %d, d == \"%s\"\n",
num, dat, dlen, d));
ELRE_DEBUG(1, (__F, "s == \"%s\"n", s));
ELRE_DEBUG(1, (__F, "s == \"%s\"\n", s));
/* copy the characters */
for (a = d + dat; (a < d + dlen) && (num > 0); num--)
@ -362,7 +369,7 @@ re_insert(EditLine *el __attribute__((__unused__)),
ELRE_DEBUG(1,
(__F, "re_insert() after copy: %d at %d max %d, %s == \"%s\"\n",
num, dat, dlen, d, s));
ELRE_DEBUG(1, (__F, "s == \"%s\"n", s));
ELRE_DEBUG(1, (__F, "s == \"%s\"\n", s));
}
@ -411,6 +418,32 @@ re__strncopy(char *a, char *b, size_t n)
*a++ = *b++;
}
/* re_clear_eol():
* Find the number of characters we need to clear till the end of line
* in order to make sure that we have cleared the previous contents of
* the line. fx and sx is the number of characters inserted or deleted
* int the first or second diff, diff is the difference between the
* number of characters between the new and old line.
*/
private void
re_clear_eol(EditLine *el, int fx, int sx, int diff)
{
ELRE_DEBUG(1, (__F, "re_clear_eol sx %d, fx %d, diff %d\n",
sx, fx, diff));
if (fx < 0)
fx = -fx;
if (sx < 0)
sx = -sx;
if (fx > diff)
diff = fx;
if (sx > diff)
diff = sx;
ELRE_DEBUG(1, (__F, "re_clear_eol %d\n", diff));
term_clear_EOL(el, diff);
}
/*****************************************************************
re_update_line() is based on finding the middle difference of each line
@ -626,7 +659,7 @@ re_update_line(EditLine *el, char *old, char *new, int i)
fx = (nsb - nfd) - (osb - ofd);
sx = (nls - nse) - (ols - ose);
ELRE_DEBUG(1, (__F, "\n"));
ELRE_DEBUG(1, (__F, "fx %d, sx %d\n", fx, sx));
ELRE_DEBUG(1, (__F, "ofd %d, osb %d, ose %d, ols %d, oe %d\n",
ofd - old, osb - old, ose - old, ols - old, oe - old));
ELRE_DEBUG(1, (__F, "nfd %d, nsb %d, nse %d, nls %d, ne %d\n",
@ -775,9 +808,7 @@ re_update_line(EditLine *el, char *old, char *new, int i)
* write (nsb-nfd) chars of new starting at nfd
*/
term_overwrite(el, nfd, (nsb - nfd));
ELRE_DEBUG(1, (__F,
"cleareol %d\n", (oe - old) - (ne - new)));
term_clear_EOL(el, (oe - old) - (ne - new));
re_clear_eol(el, fx, sx, (oe - old) - (ne - new));
/*
* Done
*/
@ -818,10 +849,7 @@ re_update_line(EditLine *el, char *old, char *new, int i)
ELRE_DEBUG(1, (__F,
"but with nothing left to save\r\n"));
term_overwrite(el, nse, (nls - nse));
ELRE_DEBUG(1, (__F,
"cleareol %d\n", (oe - old) - (ne - new)));
if ((oe - old) - (ne - new) != 0)
term_clear_EOL(el, (oe - old) - (ne - new));
re_clear_eol(el, fx, sx, (oe - old) - (ne - new));
}
}
/*
@ -982,7 +1010,7 @@ re_refresh_cursor(EditLine *el)
/* now go there */
term_move_to_line(el, v);
term_move_to_char(el, h);
term__flush();
term__flush(el);
}
@ -993,7 +1021,7 @@ private void
re_fastputc(EditLine *el, int c)
{
term__putc(c);
term__putc(el, c);
el->el_display[el->el_cursor.v][el->el_cursor.h++] = c;
if (el->el_cursor.h >= el->el_term.t_size.h) {
/* if we must overflow */
@ -1020,12 +1048,12 @@ re_fastputc(EditLine *el, int c)
}
if (EL_HAS_AUTO_MARGINS) {
if (EL_HAS_MAGIC_MARGINS) {
term__putc(' ');
term__putc('\b');
term__putc(el, ' ');
term__putc(el, '\b');
}
} else {
term__putc('\r');
term__putc('\n');
term__putc(el, '\r');
term__putc(el, '\n');
}
}
}
@ -1065,7 +1093,7 @@ re_fastaddc(EditLine *el)
re_fastputc(el, (int)(((((unsigned int)c) >> 3) & 7) + '0'));
re_fastputc(el, (c & 7) + '0');
}
term__flush();
term__flush(el);
}
@ -1104,7 +1132,7 @@ re_clear_lines(EditLine *el)
} else {
term_move_to_line(el, el->el_refresh.r_oldcv);
/* go to last line */
term__putc('\r'); /* go to BOL */
term__putc('\n'); /* go to new line */
term__putc(el, '\r'); /* go to BOL */
term__putc(el, '\n'); /* go to new line */
}
}

View file

@ -32,12 +32,17 @@
* SUCH DAMAGE.
*/
#include <config.h>
#include "config.h"
#if !defined(lint) && !defined(SCCSID)
#if 0
static char sccsid[] = "@(#)search.c 8.1 (Berkeley) 6/4/93";
#else
#endif
#endif /* not lint && not SCCSID */
/*
* search.c: History and character search functions
*/
#include <sys/types.h>
#include <stdlib.h>
#if defined(REGEX)
#include <regex.h>

View file

@ -1,4 +1,4 @@
/* $NetBSD: sig.c,v 1.11 2003/08/07 16:44:33 agc Exp $ */
/* $NetBSD: sig.c,v 1.12 2008/09/10 15:45:37 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -32,7 +32,13 @@
* SUCH DAMAGE.
*/
#include <config.h>
#include "config.h"
#if !defined(lint) && !defined(SCCSID)
#if 0
static char sccsid[] = "@(#)sig.c 8.1 (Berkeley) 6/4/93";
#else
#endif
#endif /* not lint && not SCCSID */
/*
* sig.c: Signal handling stuff.
@ -51,15 +57,15 @@ private const int sighdl[] = {
- 1
};
private void sig_handler(int);
private void el_sig_handler(int);
/* sig_handler():
/* el_sig_handler():
* This is the handler called for all signals
* XXX: we cannot pass any data so we just store the old editline
* state in a private variable
*/
private void
sig_handler(int signo)
el_sig_handler(int signo)
{
int i;
sigset_t nset, oset;
@ -73,7 +79,7 @@ sig_handler(int signo)
tty_rawmode(sel);
if (ed_redisplay(sel, 0) == CC_REFRESH)
re_refresh(sel);
term__flush();
term__flush(sel);
break;
case SIGWINCH:
@ -154,7 +160,7 @@ sig_set(EditLine *el)
for (i = 0; sighdl[i] != -1; i++) {
el_signalhandler_t s;
/* This could happen if we get interrupted */
if ((s = signal(sighdl[i], sig_handler)) != sig_handler)
if ((s = signal(sighdl[i], el_sig_handler)) != el_sig_handler)
el->el_signal[i] = s;
}
sel = el;

View file

@ -1,4 +1,4 @@
/* $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
@ -51,7 +51,6 @@
#define ALLSIGS \
_DO(SIGINT) \
_DO(SIGTSTP) \
_DO(SIGSTOP) \
_DO(SIGQUIT) \
_DO(SIGHUP) \
_DO(SIGTERM) \

View file

@ -1,73 +0,0 @@
/* $NetBSD: strlcpy.c,v 1.14 2003/10/27 00:12:42 lukem 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>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND TODD C. MILLER DISCLAIMS ALL
* WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL TODD C. MILLER BE LIABLE
* FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <config.h>
#include <sys/types.h>
#include <assert.h>
#include <string.h>
#ifdef _LIBC
# ifdef __weak_alias
__weak_alias(strlcpy, _strlcpy)
# endif
#endif
#if !HAVE_STRLCPY
/*
* Copy src to string dst of size siz. At most siz-1 characters
* will be copied. Always NUL terminates (unless siz == 0).
* Returns strlen(src); if retval >= siz, truncation occurred.
*/
size_t
#ifdef _LIBC
_strlcpy(dst, src, siz)
#else
strlcpy(dst, src, siz)
#endif
char *dst;
const char *src;
size_t siz;
{
char *d = dst;
const char *s = src;
size_t n = siz;
_DIAGASSERT(dst != NULL);
_DIAGASSERT(src != NULL);
/* Copy as many bytes as will fit */
if (n != 0 && --n != 0) {
do {
if ((*d++ = *s++) == 0)
break;
} while (--n != 0);
}
/* Not enough room in dst, add NUL and traverse rest of src */
if (n == 0) {
if (siz != 0)
*d = '\0'; /* NUL-terminate dst */
while (*s++)
;
}
return(s - src - 1); /* count does not include NUL */
}
#endif

View file

@ -1,2 +0,0 @@
size_t strlcpy(char *dst, const char *src, size_t size);
size_t strlcat(char *dst, const char *src, size_t size);

View file

@ -48,14 +48,14 @@
# define __attribute__(A)
#endif
#ifndef __P
# define __P(x) x
#endif
#ifndef _DIAGASSERT
# define _DIAGASSERT(x)
#endif
#ifndef SIZE_T_MAX
# define SIZE_T_MAX UINT_MAX
#endif
#ifndef __BEGIN_DECLS
# ifdef __cplusplus
# define __BEGIN_DECLS extern "C" {
@ -113,6 +113,25 @@ char *fgetln(FILE *fp, size_t *len);
#define REGEX /* Use POSIX.2 regular expression functions */
#undef REGEXP /* Use UNIX V8 regular expression functions */
#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
/* XXXMYSQL: Bug#10218 Command line recall rolls into segfault */
#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
#ifdef notdef
# undef REGEX
# undef REGEXP

View file

@ -1,4 +1,4 @@
/* $NetBSD: term.c,v 1.40 2004/05/22 23:21:28 christos Exp $ */
/* $NetBSD: term.c,v 1.48 2009/02/06 20:08:13 sketch Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -32,7 +32,13 @@
* SUCH DAMAGE.
*/
#include <config.h>
#include "config.h"
#if !defined(lint) && !defined(SCCSID)
#if 0
static char sccsid[] = "@(#)term.c 8.2 (Berkeley) 4/30/95";
#else
#endif
#endif /* not lint && not SCCSID */
/*
* term.c: Editor/termcap-curses interface
@ -44,21 +50,28 @@
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#if 0 /* TODO: do we need this */
#ifdef HAVE_TERMCAP_H
#include <termcap.h>
#endif
#endif
#ifdef HAVE_CURSES_H
# include <curses.h>
#elif HAVE_NCURSES_H
# include <ncurses.h>
#include <curses.h>
#endif
#ifdef HAVE_NCURSES_H
#include <ncurses.h>
#endif
/* Solaris's term.h does horrid things. */
#if (defined(HAVE_TERM_H) && !defined(_SUNOS))
# include <term.h>
#if (defined(HAVE_TERM_H) && !defined(__SunOS))
#include <term.h>
#endif
#include <sys/types.h>
#include <sys/ioctl.h>
#ifdef _REENTRANT
#include <pthread.h>
#endif
#include "el.h"
/*
@ -263,9 +276,13 @@ private int term_alloc_display(EditLine *);
private void term_alloc(EditLine *, const struct termcapstr *, const char *);
private void term_init_arrow(EditLine *);
private void term_reset_arrow(EditLine *);
private int term_putc(int);
private void term_tputs(EditLine *, const char *, int);
private FILE *term_outfile = NULL; /* XXX: How do we fix that? */
#ifdef _REENTRANT
private pthread_mutex_t term_mutex = PTHREAD_MUTEX_INITIALIZER;
#endif
private FILE *term_outfile = NULL;
/* term_setflags():
@ -313,7 +330,6 @@ term_setflags(EditLine *el)
#endif /* DEBUG_SCREEN */
}
/* term_init():
* Initialize the terminal stuff
*/
@ -339,7 +355,6 @@ term_init(EditLine *el)
if (el->el_term.t_val == NULL)
return (-1);
(void) memset(el->el_term.t_val, 0, T_val * sizeof(int));
term_outfile = el->el_outfile;
(void) term_set(el, NULL);
term_init_arrow(el);
return (0);
@ -390,7 +405,8 @@ term_alloc(EditLine *el, const struct termcapstr *t, const char *cap)
* New string is shorter; no need to allocate space
*/
if (clen <= tlen) {
(void) strcpy(*str, cap); /* XXX strcpy is safe */
if (*str)
(void) strcpy(*str, cap); /* XXX strcpy is safe */
return;
}
/*
@ -464,8 +480,12 @@ term_alloc_display(EditLine *el)
return (-1);
for (i = 0; i < c->v; i++) {
b[i] = (char *) el_malloc((size_t) (sizeof(char) * (c->h + 1)));
if (b[i] == NULL)
if (b[i] == NULL) {
while (--i >= 0)
el_free((ptr_t) b[i]);
el_free((ptr_t) b);
return (-1);
}
}
b[c->v] = NULL;
el->el_display = b;
@ -475,8 +495,12 @@ term_alloc_display(EditLine *el)
return (-1);
for (i = 0; i < c->v; i++) {
b[i] = (char *) el_malloc((size_t) (sizeof(char) * (c->h + 1)));
if (b[i] == NULL)
if (b[i] == NULL) {
while (--i >= 0)
el_free((ptr_t) b[i]);
el_free((ptr_t) b);
return (-1);
}
}
b[c->v] = NULL;
el->el_vdisplay = b;
@ -542,12 +566,12 @@ term_move_to_line(EditLine *el, int where)
del--;
} else {
if ((del > 1) && GoodStr(T_DO)) {
(void) tputs(tgoto(Str(T_DO), del, del),
del, term__putc);
term_tputs(el, tgoto(Str(T_DO), del,
del), del);
del = 0;
} else {
for (; del > 0; del--)
term__putc('\n');
term__putc(el, '\n');
/* because the \n will become \r\n */
el->el_cursor.h = 0;
}
@ -555,12 +579,11 @@ term_move_to_line(EditLine *el, int where)
}
} else { /* del < 0 */
if (GoodStr(T_UP) && (-del > 1 || !GoodStr(T_up)))
(void) tputs(tgoto(Str(T_UP), -del, -del), -del,
term__putc);
term_tputs(el, tgoto(Str(T_UP), -del, -del), -del);
else {
if (GoodStr(T_up))
for (; del < 0; del++)
(void) tputs(Str(T_up), 1, term__putc);
term_tputs(el, Str(T_up), 1);
}
}
el->el_cursor.v = where;/* now where is here */
@ -587,7 +610,7 @@ mc_again:
return;
}
if (!where) { /* if where is first column */
term__putc('\r'); /* do a CR */
term__putc(el, '\r'); /* do a CR */
el->el_cursor.h = 0;
return;
}
@ -595,12 +618,11 @@ mc_again:
if ((del < -4 || del > 4) && GoodStr(T_ch))
/* go there directly */
(void) tputs(tgoto(Str(T_ch), where, where), where, term__putc);
term_tputs(el, tgoto(Str(T_ch), where, where), where);
else {
if (del > 0) { /* moving forward */
if ((del > 4) && GoodStr(T_RI))
(void) tputs(tgoto(Str(T_RI), del, del),
del, term__putc);
term_tputs(el, tgoto(Str(T_RI), del, del), del);
else {
/* if I can do tabs, use them */
if (EL_CAN_TAB) {
@ -611,7 +633,7 @@ mc_again:
(el->el_cursor.h & 0370);
i < (where & 0370);
i += 8)
term__putc('\t');
term__putc(el, '\t');
/* then tab over */
el->el_cursor.h = where & 0370;
}
@ -631,8 +653,8 @@ mc_again:
}
} else { /* del < 0 := moving backward */
if ((-del > 4) && GoodStr(T_LE))
(void) tputs(tgoto(Str(T_LE), -del, -del),
-del, term__putc);
term_tputs(el, tgoto(Str(T_LE), -del, -del),
-del);
else { /* can't go directly there */
/*
* if the "cost" is greater than the "cost"
@ -643,12 +665,12 @@ mc_again:
(((unsigned int) where >> 3) +
(where & 07)))
: (-del > where)) {
term__putc('\r'); /* do a CR */
term__putc(el, '\r'); /* do a CR */
el->el_cursor.h = 0;
goto mc_again; /* and try again */
}
for (i = 0; i < -del; i++)
term__putc('\b');
term__putc(el, '\b');
}
}
}
@ -673,7 +695,7 @@ term_overwrite(EditLine *el, const char *cp, int n)
return;
}
do {
term__putc(*cp++);
term__putc(el, *cp++);
el->el_cursor.h++;
} while (--n);
@ -689,7 +711,7 @@ term_overwrite(EditLine *el, const char *cp, int n)
!= '\0')
term_overwrite(el, &c, 1);
else
term__putc(' ');
term__putc(el, ' ');
el->el_cursor.h = 1;
}
} else /* no wrap, but cursor stays on screen */
@ -723,19 +745,18 @@ term_deletechars(EditLine *el, int num)
if (GoodStr(T_DC)) /* if I have multiple delete */
if ((num > 1) || !GoodStr(T_dc)) { /* if dc would be more
* expen. */
(void) tputs(tgoto(Str(T_DC), num, num),
num, term__putc);
term_tputs(el, tgoto(Str(T_DC), num, num), num);
return;
}
if (GoodStr(T_dm)) /* if I have delete mode */
(void) tputs(Str(T_dm), 1, term__putc);
term_tputs(el, Str(T_dm), 1);
if (GoodStr(T_dc)) /* else do one at a time */
while (num--)
(void) tputs(Str(T_dc), 1, term__putc);
term_tputs(el, Str(T_dc), 1);
if (GoodStr(T_ed)) /* if I have delete mode */
(void) tputs(Str(T_ed), 1, term__putc);
term_tputs(el, Str(T_ed), 1);
}
@ -764,37 +785,35 @@ term_insertwrite(EditLine *el, char *cp, int num)
if (GoodStr(T_IC)) /* if I have multiple insert */
if ((num > 1) || !GoodStr(T_ic)) {
/* if ic would be more expensive */
(void) tputs(tgoto(Str(T_IC), num, num),
num, term__putc);
term_tputs(el, tgoto(Str(T_IC), num, num), num);
term_overwrite(el, cp, num);
/* this updates el_cursor.h */
return;
}
if (GoodStr(T_im) && GoodStr(T_ei)) { /* if I have insert mode */
(void) tputs(Str(T_im), 1, term__putc);
term_tputs(el, Str(T_im), 1);
el->el_cursor.h += num;
do
term__putc(*cp++);
term__putc(el, *cp++);
while (--num);
if (GoodStr(T_ip)) /* have to make num chars insert */
(void) tputs(Str(T_ip), 1, term__putc);
term_tputs(el, Str(T_ip), 1);
(void) tputs(Str(T_ei), 1, term__putc);
term_tputs(el, Str(T_ei), 1);
return;
}
do {
if (GoodStr(T_ic)) /* have to make num chars insert */
(void) tputs(Str(T_ic), 1, term__putc);
/* insert a char */
term_tputs(el, Str(T_ic), 1);
term__putc(*cp++);
term__putc(el, *cp++);
el->el_cursor.h++;
if (GoodStr(T_ip)) /* have to make num chars insert */
(void) tputs(Str(T_ip), 1, term__putc);
term_tputs(el, Str(T_ip), 1);
/* pad the inserted char */
} while (--num);
@ -810,10 +829,10 @@ term_clear_EOL(EditLine *el, int num)
int i;
if (EL_CAN_CEOL && GoodStr(T_ce))
(void) tputs(Str(T_ce), 1, term__putc);
term_tputs(el, Str(T_ce), 1);
else {
for (i = 0; i < num; i++)
term__putc(' ');
term__putc(el, ' ');
el->el_cursor.h += num; /* have written num spaces */
}
}
@ -828,14 +847,14 @@ term_clear_screen(EditLine *el)
if (GoodStr(T_cl))
/* send the clear screen code */
(void) tputs(Str(T_cl), Val(T_li), term__putc);
term_tputs(el, Str(T_cl), Val(T_li));
else if (GoodStr(T_ho) && GoodStr(T_cd)) {
(void) tputs(Str(T_ho), Val(T_li), term__putc); /* home */
term_tputs(el, Str(T_ho), Val(T_li)); /* home */
/* clear to bottom of screen */
(void) tputs(Str(T_cd), Val(T_li), term__putc);
term_tputs(el, Str(T_cd), Val(T_li));
} else {
term__putc('\r');
term__putc('\n');
term__putc(el, '\r');
term__putc(el, '\n');
}
}
@ -848,9 +867,9 @@ term_beep(EditLine *el)
{
if (GoodStr(T_bl))
/* what termcap says we should use */
(void) tputs(Str(T_bl), 1, term__putc);
term_tputs(el, Str(T_bl), 1);
else
term__putc('\007'); /* an ASCII bell; ^G */
term__putc(el, '\007'); /* an ASCII bell; ^G */
}
@ -862,9 +881,9 @@ protected void
term_clear_to_bottom(EditLine *el)
{
if (GoodStr(T_cd))
(void) tputs(Str(T_cd), Val(T_li), term__putc);
term_tputs(el, Str(T_cd), Val(T_li));
else if (GoodStr(T_ce))
(void) tputs(Str(T_ce), Val(T_li), term__putc);
term_tputs(el, Str(T_ce), Val(T_li));
}
#endif
@ -936,7 +955,7 @@ term_set(EditLine *el, const char *term)
Val(T_co) = tgetnum("co");
Val(T_li) = tgetnum("li");
for (t = tstr; t->name != NULL; t++) {
/* XXX: some systems tgetstr needs non const */
/* XXX: some systems' tgetstr needs non const */
term_alloc(el, t, tgetstr(strchr(t->name, *t->name),
&area));
}
@ -1220,26 +1239,62 @@ term_bind_arrow(EditLine *el)
}
}
/* term_putc():
* Add a character
*/
private int
term_putc(int c)
{
if (term_outfile == NULL)
return -1;
return fputc(c, term_outfile);
}
private void
term_tputs(EditLine *el, const char *cap, int affcnt)
{
#ifdef _REENTRANT
pthread_mutex_lock(&term_mutex);
#endif
term_outfile = el->el_outfile;
(void)tputs(cap, affcnt, term_putc);
#ifdef _REENTRANT
pthread_mutex_unlock(&term_mutex);
#endif
}
/* term__putc():
* Add a character
*/
protected int
term__putc(int c)
term__putc(EditLine *el, int c)
{
return (fputc(c, term_outfile));
return fputc(c, el->el_outfile);
}
/* term__flush():
* Flush output
*/
protected void
term__flush(void)
term__flush(EditLine *el)
{
(void) fflush(term_outfile);
(void) fflush(el->el_outfile);
}
/* term_writec():
* Write the given character out, in a human readable form
*/
protected void
term_writec(EditLine *el, int c)
{
char buf[8];
int cnt = key__decode_char(buf, sizeof(buf), 0, c);
buf[cnt] = '\0';
term_overwrite(el, buf, cnt);
term__flush(el);
}
@ -1269,11 +1324,17 @@ term_telltc(EditLine *el, int argc __attribute__((__unused__)),
(void) fprintf(el->el_outfile, "\tIt %s magic margins\n",
EL_HAS_MAGIC_MARGINS ? "has" : "does not have");
for (t = tstr, ts = el->el_term.t_str; t->name != NULL; t++, ts++)
for (t = tstr, ts = el->el_term.t_str; t->name != NULL; t++, ts++) {
const char *ub;
if (*ts && **ts) {
(void) key__decode_str(*ts, upbuf, sizeof(upbuf), "");
ub = upbuf;
} else {
ub = "(empty)";
}
(void) fprintf(el->el_outfile, "\t%25s (%s) == %s\n",
t->long_name,
t->name, *ts && **ts ?
key__decode_str(*ts, upbuf, "") : "(empty)");
t->long_name, t->name, ub);
}
(void) fputc('\n', el->el_outfile);
return (0);
}
@ -1292,7 +1353,7 @@ term_settc(EditLine *el, int argc __attribute__((__unused__)),
const char *what, *how;
if (argv == NULL || argv[1] == NULL || argv[2] == NULL)
return (-1);
return -1;
what = argv[1];
how = argv[2];
@ -1307,7 +1368,7 @@ term_settc(EditLine *el, int argc __attribute__((__unused__)),
if (ts->name != NULL) {
term_alloc(el, ts, how);
term_setflags(el);
return (0);
return 0;
}
/*
* Do the numeric ones second
@ -1316,46 +1377,100 @@ term_settc(EditLine *el, int argc __attribute__((__unused__)),
if (strcmp(tv->name, what) == 0)
break;
if (tv->name != NULL) {
if (tv == &tval[T_pt] || tv == &tval[T_km] ||
tv == &tval[T_am] || tv == &tval[T_xn]) {
if (strcmp(how, "yes") == 0)
el->el_term.t_val[tv - tval] = 1;
else if (strcmp(how, "no") == 0)
el->el_term.t_val[tv - tval] = 0;
else {
(void) fprintf(el->el_errfile,
"settc: Bad value `%s'.\n", how);
return (-1);
}
term_setflags(el);
if (term_change_size(el, Val(T_li), Val(T_co)) == -1)
return (-1);
return (0);
} else {
long i;
char *ep;
if (tv->name != NULL)
return -1;
i = strtol(how, &ep, 10);
if (*ep != '\0') {
(void) fprintf(el->el_errfile,
"settc: Bad value `%s'.\n", how);
return (-1);
}
el->el_term.t_val[tv - tval] = (int) i;
el->el_term.t_size.v = Val(T_co);
el->el_term.t_size.h = Val(T_li);
if (tv == &tval[T_co] || tv == &tval[T_li])
if (term_change_size(el, Val(T_li), Val(T_co))
== -1)
return (-1);
return (0);
if (tv == &tval[T_pt] || tv == &tval[T_km] ||
tv == &tval[T_am] || tv == &tval[T_xn]) {
if (strcmp(how, "yes") == 0)
el->el_term.t_val[tv - tval] = 1;
else if (strcmp(how, "no") == 0)
el->el_term.t_val[tv - tval] = 0;
else {
(void) fprintf(el->el_errfile,
"%s: Bad value `%s'.\n", argv[0], how);
return -1;
}
term_setflags(el);
if (term_change_size(el, Val(T_li), Val(T_co)) == -1)
return -1;
return 0;
} else {
long i;
char *ep;
i = strtol(how, &ep, 10);
if (*ep != '\0') {
(void) fprintf(el->el_errfile,
"%s: Bad value `%s'.\n", argv[0], how);
return -1;
}
el->el_term.t_val[tv - tval] = (int) i;
el->el_term.t_size.v = Val(T_co);
el->el_term.t_size.h = Val(T_li);
if (tv == &tval[T_co] || tv == &tval[T_li])
if (term_change_size(el, Val(T_li), Val(T_co))
== -1)
return -1;
return 0;
}
return (-1);
}
/* term_gettc():
* Get the current terminal characteristics
*/
protected int
/*ARGSUSED*/
term_gettc(EditLine *el, int argc __attribute__((__unused__)), char **argv)
{
const struct termcapstr *ts;
const struct termcapval *tv;
char *what;
void *how;
if (argv == NULL || argv[1] == NULL || argv[2] == NULL)
return (-1);
what = argv[1];
how = argv[2];
/*
* Do the strings first
*/
for (ts = tstr; ts->name != NULL; ts++)
if (strcmp(ts->name, what) == 0)
break;
if (ts->name != NULL) {
*(char **)how = el->el_term.t_str[ts - tstr];
return 0;
}
/*
* Do the numeric ones second
*/
for (tv = tval; tv->name != NULL; tv++)
if (strcmp(tv->name, what) == 0)
break;
if (tv->name == NULL)
return -1;
if (tv == &tval[T_pt] || tv == &tval[T_km] ||
tv == &tval[T_am] || tv == &tval[T_xn]) {
static char yes[] = "yes";
static char no[] = "no";
if (el->el_term.t_val[tv - tval])
*(char **)how = yes;
else
*(char **)how = no;
return 0;
} else {
*(int *)how = el->el_term.t_val[tv - tval];
return 0;
}
}
/* term_echotc():
* Print the termcap string out with variable substitution
*/
@ -1441,7 +1556,7 @@ term_echotc(EditLine *el, int argc __attribute__((__unused__)),
break;
}
if (t->name == NULL) {
/* XXX: some systems tgetstr needs non const */
/* XXX: some systems' tgetstr needs non const */
scap = tgetstr(strchr(*argv, **argv), &area);
}
if (!scap || scap[0] == '\0') {
@ -1494,7 +1609,7 @@ term_echotc(EditLine *el, int argc __attribute__((__unused__)),
*argv);
return (-1);
}
(void) tputs(scap, 1, term__putc);
term_tputs(el, scap, 1);
break;
case 1:
argv++;
@ -1522,7 +1637,7 @@ term_echotc(EditLine *el, int argc __attribute__((__unused__)),
*argv);
return (-1);
}
(void) tputs(tgoto(scap, arg_cols, arg_rows), 1, term__putc);
term_tputs(el, tgoto(scap, arg_cols, arg_rows), 1);
break;
default:
/* This is wrong, but I will ignore it... */
@ -1578,8 +1693,7 @@ term_echotc(EditLine *el, int argc __attribute__((__unused__)),
*argv);
return (-1);
}
(void) tputs(tgoto(scap, arg_cols, arg_rows), arg_rows,
term__putc);
term_tputs(el, tgoto(scap, arg_cols, arg_rows), arg_rows);
break;
}
return (0);

View file

@ -32,7 +32,13 @@
* SUCH DAMAGE.
*/
#include <config.h>
#include "config.h"
#if !defined(lint) && !defined(SCCSID)
#if 0
static char sccsid[] = "@(#)tokenizer.c 8.1 (Berkeley) 6/4/93";
#else
#endif
#endif /* not lint && not SCCSID */
/*
* tokenize.c: Bourne shell like tokenizer

View file

@ -1,54 +0,0 @@
/* $NetBSD: tokenizer.h,v 1.5 2002/03/18 16:01:00 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.
*
* @(#)tokenizer.h 8.1 (Berkeley) 6/4/93
*/
/*
* tokenizer.h: Header file for tokenizer routines
*/
#ifndef _h_tokenizer
#define _h_tokenizer
typedef struct tokenizer Tokenizer;
Tokenizer *tok_init(const char *);
void tok_reset(Tokenizer *);
void tok_end(Tokenizer *);
int tok_line(Tokenizer *, const char *, int *, const char ***);
#endif /* _h_tokenizer */

View file

@ -1,4 +1,4 @@
/* $NetBSD: tty.c,v 1.21 2004/08/13 12:10:39 mycroft Exp $ */
/* $NetBSD: tty.c,v 1.28 2009/02/06 19:53:23 sketch Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -32,18 +32,25 @@
* SUCH DAMAGE.
*/
#include <config.h>
#include "config.h"
#if !defined(lint) && !defined(SCCSID)
#if 0
static char sccsid[] = "@(#)tty.c 8.1 (Berkeley) 6/4/93";
#else
#endif
#endif /* not lint && not SCCSID */
/*
* tty.c: tty interface stuff
*/
#include <assert.h>
#include <errno.h>
#include "tty.h"
#include "el.h"
typedef struct ttymodes_t {
const char *m_name;
u_int m_value;
unsigned int m_value;
int m_type;
} ttymodes_t;
@ -438,13 +445,12 @@ private const ttymodes_t ttymodes[] = {
#define tty_getty(el, td) tcgetattr((el)->el_infd, (td))
#define tty_setty(el, td) tcsetattr((el)->el_infd, TCSADRAIN, (td))
#define tty__gettabs(td) ((((td)->c_oflag & TAB3) == TAB3) ? 0 : 1)
#define tty__geteightbit(td) (((td)->c_cflag & CSIZE) == CS8)
#define tty__cooked_mode(td) ((td)->c_lflag & ICANON)
private int tty_getty(EditLine *, struct termios *);
private int tty_setty(EditLine *, int, const struct termios *);
private int tty__getcharindex(int);
private void tty__getchar(struct termios *, unsigned char *);
private void tty__setchar(struct termios *, unsigned char *);
@ -453,6 +459,29 @@ private int tty_setup(EditLine *);
#define t_qu t_ts
/* tty_getty():
* Wrapper for tcgetattr to handle EINTR
*/
private int
tty_getty(EditLine *el, struct termios *t)
{
int rv;
while ((rv = tcgetattr(el->el_infd, t)) == -1 && errno == EINTR)
continue;
return rv;
}
/* tty_setty():
* Wrapper for tcsetattr to handle EINTR
*/
private int
tty_setty(EditLine *el, int action, const struct termios *t)
{
int rv;
while ((rv = tcsetattr(el->el_infd, action, t)) == -1 && errno == EINTR)
continue;
return rv;
}
/* tty_setup():
* Get the tty parameters and initialize the editing state
@ -514,7 +543,7 @@ tty_setup(EditLine *el)
el->el_tty.t_c[TS_IO][rst];
}
tty__setchar(&el->el_tty.t_ex, el->el_tty.t_c[EX_IO]);
if (tty_setty(el, &el->el_tty.t_ex) == -1) {
if (tty_setty(el, TCSADRAIN, &el->el_tty.t_ex) == -1) {
#ifdef DEBUG_TTY
(void) fprintf(el->el_errfile,
"tty_setup: tty_setty: %s\n",
@ -522,8 +551,11 @@ tty_setup(EditLine *el)
#endif /* DEBUG_TTY */
return (-1);
}
} else
}
#ifdef notdef
else
tty__setchar(&el->el_tty.t_ex, el->el_tty.t_c[EX_IO]);
#endif
el->el_tty.t_ed.c_iflag &= ~el->el_tty.t_t[ED_IO][MD_INP].t_clrmask;
el->el_tty.t_ed.c_iflag |= el->el_tty.t_t[ED_IO][MD_INP].t_setmask;
@ -1040,7 +1072,7 @@ tty_rawmode(EditLine *el)
}
}
}
if (tty_setty(el, &el->el_tty.t_ed) == -1) {
if (tty_setty(el, TCSADRAIN, &el->el_tty.t_ed) == -1) {
#ifdef DEBUG_TTY
(void) fprintf(el->el_errfile, "tty_rawmode: tty_setty: %s\n",
strerror(errno));
@ -1065,7 +1097,7 @@ tty_cookedmode(EditLine *el)
if (el->el_flags & EDIT_DISABLED)
return (0);
if (tty_setty(el, &el->el_tty.t_ex) == -1) {
if (tty_setty(el, TCSADRAIN, &el->el_tty.t_ex) == -1) {
#ifdef DEBUG_TTY
(void) fprintf(el->el_errfile,
"tty_cookedmode: tty_setty: %s\n",
@ -1101,7 +1133,7 @@ tty_quotemode(EditLine *el)
el->el_tty.t_qu.c_lflag &= ~el->el_tty.t_t[QU_IO][MD_LIN].t_clrmask;
el->el_tty.t_qu.c_lflag |= el->el_tty.t_t[QU_IO][MD_LIN].t_setmask;
if (tty_setty(el, &el->el_tty.t_qu) == -1) {
if (tty_setty(el, TCSADRAIN, &el->el_tty.t_qu) == -1) {
#ifdef DEBUG_TTY
(void) fprintf(el->el_errfile, "QuoteModeOn: tty_setty: %s\n",
strerror(errno));
@ -1122,7 +1154,7 @@ tty_noquotemode(EditLine *el)
if (el->el_tty.t_mode != QU_IO)
return (0);
if (tty_setty(el, &el->el_tty.t_ed) == -1) {
if (tty_setty(el, TCSADRAIN, &el->el_tty.t_ed) == -1) {
#ifdef DEBUG_TTY
(void) fprintf(el->el_errfile, "QuoteModeOff: tty_setty: %s\n",
strerror(errno));
@ -1193,10 +1225,14 @@ tty_stty(EditLine *el, int argc __attribute__((__unused__)), const char **argv)
st = len =
strlen(el->el_tty.t_t[z][m->m_type].t_name);
}
x = (el->el_tty.t_t[z][i].t_setmask & m->m_value)
? '+' : '\0';
x = (el->el_tty.t_t[z][i].t_clrmask & m->m_value)
? '-' : x;
if (i != -1) {
x = (el->el_tty.t_t[z][i].t_setmask & m->m_value)
? '+' : '\0';
x = (el->el_tty.t_t[z][i].t_clrmask & m->m_value)
? '-' : x;
} else {
x = '\0';
}
if (x != '\0' || aflag) {
@ -1221,7 +1257,7 @@ tty_stty(EditLine *el, int argc __attribute__((__unused__)), const char **argv)
return (0);
}
while (argv && (s = *argv++)) {
char *p;
const char *p;
switch (*s) {
case '+':
case '-':
@ -1232,10 +1268,10 @@ tty_stty(EditLine *el, int argc __attribute__((__unused__)), const char **argv)
break;
}
d = s;
if ((p = strchr(s, '=')) != NULL)
*p++ = '\0';
p = strchr(s, '=');
for (m = ttymodes; m->m_name; m++)
if (strcmp(m->m_name, d) == 0 &&
if ((p ? strncmp(m->m_name, d, (size_t)(p - d)) :
strcmp(m->m_name, d)) == 0 &&
(p == NULL || m->m_type == MD_CHAR))
break;
@ -1246,7 +1282,7 @@ tty_stty(EditLine *el, int argc __attribute__((__unused__)), const char **argv)
}
if (p) {
int c = ffs((int)m->m_value);
int v = *p ? parse__escape((const char **const) &p) :
int v = *++p ? parse__escape((const char **) &p) :
el->el_tty.t_vdisable;
assert(c-- != 0);
c = tty__getcharindex(c);
@ -1269,6 +1305,17 @@ tty_stty(EditLine *el, int argc __attribute__((__unused__)), const char **argv)
break;
}
}
if (el->el_tty.t_mode == z) {
if (tty_setty(el, TCSADRAIN, tios) == -1) {
#ifdef DEBUG_TTY
(void) fprintf(el->el_errfile,
"tty_stty: tty_setty: %s\n", strerror(errno));
#endif /* DEBUG_TTY */
return (-1);
}
}
return (0);
}

View file

@ -1,4 +1,4 @@
/* $NetBSD: tty.h,v 1.10 2003/08/07 16:44:34 agc Exp $ */
/* $NetBSD: tty.h,v 1.11 2005/06/01 11:37:52 lukem Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -450,8 +450,8 @@
typedef struct {
const char *t_name;
u_int t_setmask;
u_int t_clrmask;
unsigned int t_setmask;
unsigned int t_clrmask;
} ttyperm_t[NN_IO][MD_NN];
typedef unsigned char ttychar_t[NN_IO][C_NCC];

View file

@ -1,311 +0,0 @@
/* $NetBSD: unvis.c,v 1.24 2003/08/07 16:42:59 agc Exp $ */
/*-
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. 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 <config.h>
#define __LIBC12_SOURCE__
#include <sys/types.h>
#include <assert.h>
#include <ctype.h>
#include <stdio.h>
#include <vis.h>
#ifdef __weak_alias
__weak_alias(strunvis,_strunvis)
__weak_alias(unvis,_unvis)
#endif
#ifdef __warn_references
__warn_references(unvis,
"warning: reference to compatibility unvis(); include <vis.h> for correct reference")
#endif
#if !HAVE_VIS
/*
* decode driven by state machine
*/
#define S_GROUND 0 /* haven't seen escape char */
#define S_START 1 /* start decoding special sequence */
#define S_META 2 /* metachar started (M) */
#define S_META1 3 /* metachar more, regular char (-) */
#define S_CTRL 4 /* control char started (^) */
#define S_OCTAL2 5 /* octal digit 2 */
#define S_OCTAL3 6 /* octal digit 3 */
#define S_HEX1 7 /* hex digit */
#define S_HEX2 8 /* hex digit 2 */
#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7')
#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
*/
int
__unvis13(cp, c, astate, flag)
char *cp;
int c;
int *astate, flag;
{
_DIAGASSERT(cp != NULL);
_DIAGASSERT(astate != NULL);
if (flag & UNVIS_END) {
if (*astate == S_OCTAL2 || *astate == S_OCTAL3
|| *astate == S_HEX2) {
*astate = S_GROUND;
return (UNVIS_VALID);
}
return (*astate == S_GROUND ? UNVIS_NOCHAR : UNVIS_SYNBAD);
}
switch (*astate) {
case S_GROUND:
*cp = 0;
if (c == '\\') {
*astate = S_START;
return (0);
}
if ((flag & VIS_HTTPSTYLE) && c == '%') {
*astate = S_HEX1;
return (0);
}
*cp = c;
return (UNVIS_VALID);
case S_START:
switch(c) {
case '\\':
*cp = c;
*astate = S_GROUND;
return (UNVIS_VALID);
case '0': case '1': case '2': case '3':
case '4': case '5': case '6': case '7':
*cp = (c - '0');
*astate = S_OCTAL2;
return (0);
case 'M':
*cp = (char)0200;
*astate = S_META;
return (0);
case '^':
*astate = S_CTRL;
return (0);
case 'n':
*cp = '\n';
*astate = S_GROUND;
return (UNVIS_VALID);
case 'r':
*cp = '\r';
*astate = S_GROUND;
return (UNVIS_VALID);
case 'b':
*cp = '\b';
*astate = S_GROUND;
return (UNVIS_VALID);
case 'a':
*cp = '\007';
*astate = S_GROUND;
return (UNVIS_VALID);
case 'v':
*cp = '\v';
*astate = S_GROUND;
return (UNVIS_VALID);
case 't':
*cp = '\t';
*astate = S_GROUND;
return (UNVIS_VALID);
case 'f':
*cp = '\f';
*astate = S_GROUND;
return (UNVIS_VALID);
case 's':
*cp = ' ';
*astate = S_GROUND;
return (UNVIS_VALID);
case 'E':
*cp = '\033';
*astate = S_GROUND;
return (UNVIS_VALID);
case '\n':
/*
* hidden newline
*/
*astate = S_GROUND;
return (UNVIS_NOCHAR);
case '$':
/*
* hidden marker
*/
*astate = S_GROUND;
return (UNVIS_NOCHAR);
}
*astate = S_GROUND;
return (UNVIS_SYNBAD);
case S_META:
if (c == '-')
*astate = S_META1;
else if (c == '^')
*astate = S_CTRL;
else {
*astate = S_GROUND;
return (UNVIS_SYNBAD);
}
return (0);
case S_META1:
*astate = S_GROUND;
*cp |= c;
return (UNVIS_VALID);
case S_CTRL:
if (c == '?')
*cp |= 0177;
else
*cp |= c & 037;
*astate = S_GROUND;
return (UNVIS_VALID);
case S_OCTAL2: /* second possible octal digit */
if (isoctal(c)) {
/*
* yes - and maybe a third
*/
*cp = (*cp << 3) + (c - '0');
*astate = S_OCTAL3;
return (0);
}
/*
* no - done with current sequence, push back passed char
*/
*astate = S_GROUND;
return (UNVIS_VALIDPUSH);
case S_OCTAL3: /* third possible octal digit */
*astate = S_GROUND;
if (isoctal(c)) {
*cp = (*cp << 3) + (c - '0');
return (UNVIS_VALID);
}
/*
* we were done, push back passed char
*/
return (UNVIS_VALIDPUSH);
case S_HEX1:
if (isxdigit(c)) {
*cp = xtod(c);
*astate = S_HEX2;
return (0);
}
/*
* no - done with current sequence, push back passed char
*/
*astate = S_GROUND;
return (UNVIS_VALIDPUSH);
case S_HEX2:
*astate = S_GROUND;
if (isxdigit(c)) {
*cp = xtod(c) | (*cp << 4);
return (UNVIS_VALID);
}
return (UNVIS_VALIDPUSH);
default:
/*
* decoder in unknown state - (probably uninitialized)
*/
*astate = S_GROUND;
return (UNVIS_SYNBAD);
}
}
/*
* strunvis - decode src into dst
*
* Number of chars decoded into dst is returned, -1 on error.
* Dst is null terminated.
*/
int
strunvisx(dst, src, flag)
char *dst;
const char *src;
int flag;
{
char c;
char *start = dst;
int state = 0;
_DIAGASSERT(src != NULL);
_DIAGASSERT(dst != NULL);
while ((c = *src++) != '\0') {
again:
switch (__unvis13(dst, c, &state, flag)) {
case UNVIS_VALID:
dst++;
break;
case UNVIS_VALIDPUSH:
dst++;
goto again;
case 0:
case UNVIS_NOCHAR:
break;
default:
return (-1);
}
}
if (__unvis13(dst, c, &state, UNVIS_END) == UNVIS_VALID)
dst++;
*dst = '\0';
return (dst - start);
}
int
strunvis(dst, src)
char *dst;
const char *src;
{
return strunvisx(dst, src, 0);
}
#endif

View file

@ -1,4 +1,4 @@
/* $NetBSD: vi.c,v 1.20 2004/08/13 12:10:39 mycroft Exp $ */
/* $NetBSD: vi.c,v 1.28 2009/02/06 13:14:37 sketch Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -32,11 +32,17 @@
* SUCH DAMAGE.
*/
#include <config.h>
#include "config.h"
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#if !defined(lint) && !defined(SCCSID)
#if 0
static char sccsid[] = "@(#)vi.c 8.1 (Berkeley) 6/4/93";
#else
#endif
#endif /* not lint && not SCCSID */
/*
* vi.c: Vi mode commands.
@ -64,8 +70,10 @@ cv_action(EditLine *el, int c)
el->el_line.lastchar - el->el_line.buffer);
el->el_chared.c_vcmd.action = NOP;
el->el_chared.c_vcmd.pos = 0;
el->el_line.lastchar = el->el_line.buffer;
el->el_line.cursor = el->el_line.buffer;
if (!(c & YANK)) {
el->el_line.lastchar = el->el_line.buffer;
el->el_line.cursor = el->el_line.buffer;
}
if (c & INSERT)
el->el_map.current = el->el_map.key;
@ -82,7 +90,6 @@ cv_action(EditLine *el, int c)
private el_action_t
cv_paste(EditLine *el, int c)
{
char *ptr;
c_kill_t *k = &el->el_chared.c_kill;
int len = k->last - k->buf;
@ -96,12 +103,12 @@ cv_paste(EditLine *el, int c)
if (!c && el->el_line.cursor < el->el_line.lastchar)
el->el_line.cursor++;
ptr = el->el_line.cursor;
c_insert(el, len);
if (el->el_line.cursor + len > el->el_line.lastchar)
return (CC_ERROR);
(void) memcpy(ptr, k->buf, len +0u);
(void) memcpy(el->el_line.cursor, k->buf, len +0u);
return (CC_REFRESH);
}
@ -592,13 +599,12 @@ vi_delete_prev_char(EditLine *el, int c __attribute__((__unused__)))
*/
protected el_action_t
/*ARGSUSED*/
vi_list_or_eof(EditLine *el, int c __attribute__((__unused__)))
vi_list_or_eof(EditLine *el, int c)
{
if (el->el_line.cursor == el->el_line.lastchar) {
if (el->el_line.cursor == el->el_line.buffer) {
term_overwrite(el, STReof, 4); /* then do a EOF */
term__flush();
term_writec(el, c); /* then do a EOF */
return (CC_EOF);
} else {
/*
@ -888,7 +894,7 @@ vi_yank(EditLine *el, int c)
/* vi_comment_out():
* Vi comment out current command
* [c]
* [#]
*/
protected el_action_t
/*ARGSUSED*/
@ -905,18 +911,19 @@ vi_comment_out(EditLine *el, int c)
/* vi_alias():
* Vi include shell alias
* [@]
* NB: posix impiles that we should enter insert mode, however
* NB: posix implies that we should enter insert mode, however
* this is against historical precedent...
*/
#ifdef __weak_reference
extern char *get_alias_text(const char *) __weak_reference(get_alias_text);
#endif
protected el_action_t
/*ARGSUSED*/
vi_alias(EditLine *el, int c)
{
#ifdef __weak_extern
#ifdef __weak_reference
char alias_name[3];
char *alias_text;
extern char *get_alias_text(const char *);
__weak_extern(get_alias_text);
if (get_alias_text == 0) {
return CC_ERROR;
@ -1014,7 +1021,7 @@ vi_histedit(EditLine *el, int c)
return CC_ERROR;
case 0:
close(fd);
execlp("vi", "vi", tempfile, (char *) NULL);
execlp("vi", "vi", tempfile, (char *)NULL);
exit(0);
/*NOTREACHED*/
default:

View file

@ -1,392 +0,0 @@
/* $NetBSD: vis.c,v 1.27 2004/02/26 23:01:15 enami Exp $ */
/*-
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the 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.
*/
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
*
* 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.
*/
/* AIX requires this to be the first thing in the file. */
#if defined (_AIX) && !defined (__GNUC__)
#pragma alloca
#endif
#include <config.h>
#ifdef __GNUC__
# undef alloca
# define alloca(n) __builtin_alloca (n)
#else
# ifdef HAVE_ALLOCA_H
# include <alloca.h>
# else
# ifndef _AIX
extern char *alloca ();
# endif
# endif
#endif
#include <sys/types.h>
#include <assert.h>
#include <vis.h>
#include <stdlib.h>
#ifdef __weak_alias
__weak_alias(strsvis,_strsvis)
__weak_alias(strsvisx,_strsvisx)
__weak_alias(strvis,_strvis)
__weak_alias(strvisx,_strvisx)
__weak_alias(svis,_svis)
__weak_alias(vis,_vis)
#endif
#if !HAVE_VIS || !HAVE_SVIS
#include <ctype.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
#undef BELL
#define BELL '\a'
#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7')
#define iswhite(c) (c == ' ' || c == '\t' || c == '\n')
#define issafe(c) (c == '\b' || c == BELL || c == '\r')
#define xtoa(c) "0123456789abcdef"[c]
#define MAXEXTRAS 5
#define MAKEEXTRALIST(flag, extra, orig) \
do { \
const char *o = orig; \
char *e; \
while (*o++) \
continue; \
extra = alloca((size_t)((o - orig) + MAXEXTRAS)); \
for (o = orig, e = extra; (*e++ = *o++) != '\0';) \
continue; \
e--; \
if (flag & VIS_SP) *e++ = ' '; \
if (flag & VIS_TAB) *e++ = '\t'; \
if (flag & VIS_NL) *e++ = '\n'; \
if ((flag & VIS_NOSLASH) == 0) *e++ = '\\'; \
*e = '\0'; \
} while (/*CONSTCOND*/0)
/*
* This is HVIS, the macro of vis used to HTTP style (RFC 1808)
*/
#define HVIS(dst, c, flag, nextc, extra) \
do \
if (!isascii(c) || !isalnum(c) || strchr("$-_.+!*'(),", c) != NULL) { \
*dst++ = '%'; \
*dst++ = xtoa(((unsigned int)c >> 4) & 0xf); \
*dst++ = xtoa((unsigned int)c & 0xf); \
} else { \
SVIS(dst, c, flag, nextc, extra); \
} \
while (/*CONSTCOND*/0)
/*
* This is SVIS, the central macro of vis.
* dst: Pointer to the destination buffer
* c: Character to encode
* flag: Flag word
* nextc: The character following 'c'
* extra: Pointer to the list of extra characters to be
* backslash-protected.
*/
#define SVIS(dst, c, flag, nextc, extra) \
do { \
int isextra; \
isextra = strchr(extra, c) != NULL; \
if (!isextra && isascii(c) && (isgraph(c) || iswhite(c) || \
((flag & VIS_SAFE) && issafe(c)))) { \
*dst++ = c; \
break; \
} \
if (flag & VIS_CSTYLE) { \
switch (c) { \
case '\n': \
*dst++ = '\\'; *dst++ = 'n'; \
continue; \
case '\r': \
*dst++ = '\\'; *dst++ = 'r'; \
continue; \
case '\b': \
*dst++ = '\\'; *dst++ = 'b'; \
continue; \
case BELL: \
*dst++ = '\\'; *dst++ = 'a'; \
continue; \
case '\v': \
*dst++ = '\\'; *dst++ = 'v'; \
continue; \
case '\t': \
*dst++ = '\\'; *dst++ = 't'; \
continue; \
case '\f': \
*dst++ = '\\'; *dst++ = 'f'; \
continue; \
case ' ': \
*dst++ = '\\'; *dst++ = 's'; \
continue; \
case '\0': \
*dst++ = '\\'; *dst++ = '0'; \
if (isoctal(nextc)) { \
*dst++ = '0'; \
*dst++ = '0'; \
} \
continue; \
default: \
if (isgraph(c)) { \
*dst++ = '\\'; *dst++ = c; \
continue; \
} \
} \
} \
if (isextra || ((c & 0177) == ' ') || (flag & VIS_OCTAL)) { \
*dst++ = '\\'; \
*dst++ = (u_char)(((u_int32_t)(u_char)c >> 6) & 03) + '0'; \
*dst++ = (u_char)(((u_int32_t)(u_char)c >> 3) & 07) + '0'; \
*dst++ = (c & 07) + '0'; \
} else { \
if ((flag & VIS_NOSLASH) == 0) *dst++ = '\\'; \
if (c & 0200) { \
c &= 0177; *dst++ = 'M'; \
} \
if (iscntrl(c)) { \
*dst++ = '^'; \
if (c == 0177) \
*dst++ = '?'; \
else \
*dst++ = c + '@'; \
} else { \
*dst++ = '-'; *dst++ = c; \
} \
} \
} while (/*CONSTCOND*/0)
/*
* svis - visually encode characters, also encoding the characters
* pointed to by `extra'
*/
char *
svis(dst, c, flag, nextc, extra)
char *dst;
int c, flag, nextc;
const char *extra;
{
char *nextra;
_DIAGASSERT(dst != NULL);
_DIAGASSERT(extra != NULL);
MAKEEXTRALIST(flag, nextra, extra);
if (flag & VIS_HTTPSTYLE)
HVIS(dst, c, flag, nextc, nextra);
else
SVIS(dst, c, flag, nextc, nextra);
*dst = '\0';
return(dst);
}
/*
* strsvis, strsvisx - visually encode characters from src into dst
*
* Extra is a pointer to a \0-terminated list of characters to
* be encoded, too. These functions are useful e. g. to
* encode strings in such a way so that they are not interpreted
* by a shell.
*
* Dst must be 4 times the size of src to account for possible
* expansion. The length of dst, not including the trailing NULL,
* is returned.
*
* Strsvisx encodes exactly len bytes from src into dst.
* This is useful for encoding a block of data.
*/
int
strsvis(dst, csrc, flag, extra)
char *dst;
const char *csrc;
int flag;
const char *extra;
{
int c;
char *start;
char *nextra;
const unsigned char *src = (const unsigned char *)csrc;
_DIAGASSERT(dst != NULL);
_DIAGASSERT(src != NULL);
_DIAGASSERT(extra != NULL);
MAKEEXTRALIST(flag, nextra, extra);
if (flag & VIS_HTTPSTYLE) {
for (start = dst; (c = *src++) != '\0'; /* empty */)
HVIS(dst, c, flag, *src, nextra);
} else {
for (start = dst; (c = *src++) != '\0'; /* empty */)
SVIS(dst, c, flag, *src, nextra);
}
*dst = '\0';
return (dst - start);
}
int
strsvisx(dst, csrc, len, flag, extra)
char *dst;
const char *csrc;
size_t len;
int flag;
const char *extra;
{
int c;
char *start;
char *nextra;
const unsigned char *src = (const unsigned char *)csrc;
_DIAGASSERT(dst != NULL);
_DIAGASSERT(src != NULL);
_DIAGASSERT(extra != NULL);
MAKEEXTRALIST(flag, nextra, extra);
if (flag & VIS_HTTPSTYLE) {
for (start = dst; len > 0; len--) {
c = *src++;
HVIS(dst, c, flag, len ? *src : '\0', nextra);
}
} else {
for (start = dst; len > 0; len--) {
c = *src++;
SVIS(dst, c, flag, len ? *src : '\0', nextra);
}
}
*dst = '\0';
return (dst - start);
}
#endif
#if !HAVE_VIS
/*
* vis - visually encode characters
*/
char *
vis(dst, c, flag, nextc)
char *dst;
int c, flag, nextc;
{
char *extra;
_DIAGASSERT(dst != NULL);
MAKEEXTRALIST(flag, extra, "");
if (flag & VIS_HTTPSTYLE)
HVIS(dst, c, flag, nextc, extra);
else
SVIS(dst, c, flag, nextc, extra);
*dst = '\0';
return (dst);
}
/*
* strvis, strvisx - visually encode characters from src into dst
*
* Dst must be 4 times the size of src to account for possible
* expansion. The length of dst, not including the trailing NULL,
* is returned.
*
* Strvisx encodes exactly len bytes from src into dst.
* This is useful for encoding a block of data.
*/
int
strvis(dst, src, flag)
char *dst;
const char *src;
int flag;
{
char *extra;
MAKEEXTRALIST(flag, extra, "");
return (strsvis(dst, src, flag, extra));
}
int
strvisx(dst, src, len, flag)
char *dst;
const char *src;
size_t len;
int flag;
{
char *extra;
MAKEEXTRALIST(flag, extra, "");
return (strsvisx(dst, src, len, flag, extra));
}
#endif

View file

@ -1,92 +0,0 @@
/* $NetBSD: vis.h,v 1.15 2005/02/03 04:39:32 perry Exp $ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. 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.
*
* @(#)vis.h 8.1 (Berkeley) 6/2/93
*/
#ifndef _VIS_H_
#define _VIS_H_
#include <config.h>
/*
* to select alternate encoding format
*/
#define VIS_OCTAL 0x01 /* use octal \ddd format */
#define VIS_CSTYLE 0x02 /* use \[nrft0..] where appropiate */
/*
* to alter set of characters encoded (default is to encode all
* non-graphic except space, tab, and newline).
*/
#define VIS_SP 0x04 /* also encode space */
#define VIS_TAB 0x08 /* also encode tab */
#define VIS_NL 0x10 /* also encode newline */
#define VIS_WHITE (VIS_SP | VIS_TAB | VIS_NL)
#define VIS_SAFE 0x20 /* only encode "unsafe" characters */
/*
* other
*/
#define VIS_NOSLASH 0x40 /* inhibit printing '\' */
#define VIS_HTTPSTYLE 0x80 /* http-style escape % HEX HEX */
/*
* unvis return codes
*/
#define UNVIS_VALID 1 /* character valid */
#define UNVIS_VALIDPUSH 2 /* character valid, push back passed char */
#define UNVIS_NOCHAR 3 /* valid sequence, no character produced */
#define UNVIS_SYNBAD -1 /* unrecognized escape sequence */
#define UNVIS_ERROR -2 /* decoder in unknown state (unrecoverable) */
/*
* unvis flags
*/
#define UNVIS_END 1 /* no more characters */
__BEGIN_DECLS
char *vis(char *, int, int, int);
char *svis(char *, int, int, int, const char *);
int strvis(char *, const char *, int);
int strsvis(char *, const char *, int, const char *);
int strvisx(char *, const char *, size_t, int);
int strsvisx(char *, const char *, size_t, int, const char *);
int strunvis(char *, const char *);
int strunvisx(char *, const char *, int);
#ifdef __LIBC12_SOURCE__
int unvis(char *, int, int *, int);
int __unvis13(char *, int, int *, int);
#else
int unvis(char *, int, int *, int);
#endif
__END_DECLS
#endif /* !_VIS_H_ */

View file

@ -5,6 +5,9 @@ dnl you must also create strings/ctype-$charset_name.c
AC_DIVERT_PUSH(0)
# Any changes to the available character sets must also go into
# include/config-win.h
define(CHARSETS_AVAILABLE0,binary)
define(CHARSETS_AVAILABLE1,armscii8 ascii big5 cp1250 cp1251 cp1256 cp1257)
define(CHARSETS_AVAILABLE2,cp850 cp852 cp866 cp932 dec8 eucjpms euckr gb2312 gbk geostd8)

View file

@ -280,7 +280,7 @@ AC_DEFUN([MYSQL_SETUP_NDBCLUSTER], [
esac
# libndbclient versioning when linked with GNU ld.
if $LD --version 2>/dev/null|grep -q GNU; then
if $LD --version 2>/dev/null|grep GNU >/dev/null 2>&1 ; then
NDB_LD_VERSION_SCRIPT="-Wl,--version-script=\$(top_builddir)/storage/ndb/src/libndb.ver"
AC_CONFIG_FILES(storage/ndb/src/libndb.ver)
fi

View file

@ -10,7 +10,7 @@ AC_CANONICAL_SYSTEM
#
# When changing major version number please also check switch statement
# in mysqlbinlog::check_master_version().
AM_INIT_AUTOMAKE(mysql, 5.1.31-pv-0.2.1)
AM_INIT_AUTOMAKE(mysql, 5.1.33-pv-0.2.1)
AM_CONFIG_HEADER([include/config.h:config.h.in])
PROTOCOL_VERSION=10
@ -378,7 +378,7 @@ fi
MYSQL_PROG_AR
# libmysqlclient versioning when linked with GNU ld.
if $LD --version 2>/dev/null|grep -q GNU; then
if $LD --version 2>/dev/null| grep GNU >/dev/null 2>&1; then
LD_VERSION_SCRIPT="-Wl,--version-script=\$(top_builddir)/libmysql/libmysql.ver"
AC_CONFIG_FILES(libmysql/libmysql.ver)
fi
@ -450,11 +450,11 @@ AC_SUBST(PERL5)
# Enable the abi_check rule only if gcc is available
if expr "$CC" : ".*gcc.*"
if test "$GCC" != "yes" || expr "$CC" : ".*icc.*"
then
ABI_CHECK="abi_check"
else
ABI_CHECK=""
else
ABI_CHECK="abi_check"
fi
AC_SUBST(ABI_CHECK)
@ -2091,7 +2091,7 @@ AC_CHECK_FUNCS(alarm bcmp bfill bmove bsearch bzero \
mkstemp mlockall perror poll pread pthread_attr_create mmap mmap64 getpagesize \
pthread_attr_getstacksize pthread_attr_setprio pthread_attr_setschedparam \
pthread_attr_setstacksize pthread_condattr_create pthread_getsequence_np \
pthread_key_delete pthread_rwlock_rdlock pthread_setprio pthread_setschedprio \
pthread_key_delete pthread_rwlock_rdlock pthread_setprio \
pthread_setprio_np pthread_setschedparam pthread_sigmask readlink \
realpath rename rint rwlock_init setupterm \
shmget shmat shmdt shmctl sigaction sigemptyset sigaddset \
@ -2114,6 +2114,15 @@ case "$target" in
;;
esac
case "$mysql_cv_sys_os" in
OS400) # i5/OS (OS/400) emits a SIGILL (Function not implemented) when
# unsupported priority values are passed to pthread_setschedprio.
# Since the only supported value is 1, treat it as inexistent.
;;
*) AC_CHECK_FUNCS(pthread_setschedprio)
;;
esac
# Check that isinf() is available in math.h and can be used in both C and C++
# code
AC_MSG_CHECKING(for isinf in <math.h>)
@ -2863,8 +2872,8 @@ AC_CONFIG_FILES(Makefile extra/Makefile mysys/Makefile dnl
support-files/MacOSX/Makefile support-files/RHEL4-SElinux/Makefile dnl
cmd-line-utils/Makefile cmd-line-utils/libedit/Makefile dnl
libmysqld/Makefile libmysqld/examples/Makefile dnl
mysql-test/Makefile dnl
mysql-test/ndb/Makefile netware/Makefile sql-bench/Makefile dnl
mysql-test/Makefile mysql-test/lib/My/SafeProcess/Makefile dnl
netware/Makefile sql-bench/Makefile dnl
include/mysql_version.h plugin/Makefile win/Makefile)
AC_CONFIG_COMMANDS([default], , test -z "$CONFIG_HEADERS" || echo timestamp > stamp-h)

View file

@ -290,7 +290,8 @@ static void do_resolve()
char buf[1024], *p;
while (fgets(buf, sizeof(buf), fp_dump))
{
p = buf;
/* skip bracket */
p= (p= strchr(buf, '[')) ? p+1 : buf;
/* skip space */
while (my_isspace(&my_charset_latin1,*p))
++p;

View file

@ -203,8 +203,8 @@ SSL_CTX* SSL_CTX_new(SSL_METHOD*);
SSL* SSL_new(SSL_CTX*);
int SSL_set_fd (SSL*, YASSL_SOCKET_T);
YASSL_SOCKET_T SSL_get_fd(const SSL*);
int SSL_connect(SSL*); // if you get an error from connect
// see note at top of REAMDE
int SSL_connect(SSL*); /* if you get an error from connect
see note at top of REAMDE */
int SSL_write(SSL*, const void*, int);
int SSL_read(SSL*, void*, int);
int SSL_accept(SSL*);

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2000 MySQL AB
/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -197,11 +197,6 @@ typedef uint rf_SetTimer;
#define SIGNAL_WITH_VIO_CLOSE
#endif
/* Use all character sets in MySQL */
#define USE_MB 1
#define USE_MB_IDENT 1
#define USE_STRCOLL 1
/* All windows servers should support .sym files */
#undef USE_SYMDIR
#define USE_SYMDIR
@ -250,6 +245,15 @@ inline double ulonglong2double(ulonglong value)
#define my_off_t2double(A) ulonglong2double(A)
#endif /* _WIN64 */
inline ulonglong double2ulonglong(double d)
{
double t= d - (double) 0x8000000000000000ULL;
if (t >= 0)
return ((ulonglong) t) + 0x8000000000000000ULL;
return (ulonglong) d;
}
#if SIZEOF_OFF_T > 4
#define lseek(A,B,C) _lseeki64((A),(longlong) (B),(C))
#define tell(A) _telli64(A)
@ -362,49 +366,63 @@ inline double ulonglong2double(ulonglong value)
#define shared_memory_buffer_length 16000
#define default_shared_memory_base_name "MYSQL"
#define MYSQL_DEFAULT_CHARSET_NAME "latin1"
#define MYSQL_DEFAULT_COLLATION_NAME "latin1_swedish_ci"
#define HAVE_SPATIAL 1
#define HAVE_RTREE_KEYS 1
#define HAVE_OPENSSL 1
#define HAVE_YASSL 1
/* Define charsets you want */
/* #undef HAVE_CHARSET_armscii8 */
/* #undef HAVE_CHARSET_ascii */
#define COMMUNITY_SERVER 1
#define ENABLED_PROFILING 1
/*
Our Windows binaries include all character sets which MySQL supports.
Any changes to the available character sets must also go into
config/ac-macros/character_sets.m4
*/
#define MYSQL_DEFAULT_CHARSET_NAME "latin1"
#define MYSQL_DEFAULT_COLLATION_NAME "latin1_swedish_ci"
#define USE_MB 1
#define USE_MB_IDENT 1
#define USE_STRCOLL 1
#define HAVE_CHARSET_armscii8
#define HAVE_CHARSET_ascii
#define HAVE_CHARSET_big5 1
#define HAVE_CHARSET_cp1250 1
/* #undef HAVE_CHARSET_cp1251 */
/* #undef HAVE_CHARSET_cp1256 */
/* #undef HAVE_CHARSET_cp1257 */
/* #undef HAVE_CHARSET_cp850 */
/* #undef HAVE_CHARSET_cp852 */
/* #undef HAVE_CHARSET_cp866 */
#define HAVE_CHARSET_cp1251
#define HAVE_CHARSET_cp1256
#define HAVE_CHARSET_cp1257
#define HAVE_CHARSET_cp850
#define HAVE_CHARSET_cp852
#define HAVE_CHARSET_cp866
#define HAVE_CHARSET_cp932 1
/* #undef HAVE_CHARSET_dec8 */
#define HAVE_CHARSET_dec8
#define HAVE_CHARSET_eucjpms 1
#define HAVE_CHARSET_euckr 1
#define HAVE_CHARSET_gb2312 1
#define HAVE_CHARSET_gbk 1
/* #undef HAVE_CHARSET_greek */
/* #undef HAVE_CHARSET_hebrew */
/* #undef HAVE_CHARSET_hp8 */
/* #undef HAVE_CHARSET_keybcs2 */
/* #undef HAVE_CHARSET_koi8r */
/* #undef HAVE_CHARSET_koi8u */
#define HAVE_CHARSET_geostd8
#define HAVE_CHARSET_greek
#define HAVE_CHARSET_hebrew
#define HAVE_CHARSET_hp8
#define HAVE_CHARSET_keybcs2
#define HAVE_CHARSET_koi8r
#define HAVE_CHARSET_koi8u
#define HAVE_CHARSET_latin1 1
#define HAVE_CHARSET_latin2 1
/* #undef HAVE_CHARSET_latin5 */
/* #undef HAVE_CHARSET_latin7 */
/* #undef HAVE_CHARSET_macce */
/* #undef HAVE_CHARSET_macroman */
#define HAVE_CHARSET_latin5
#define HAVE_CHARSET_latin7
#define HAVE_CHARSET_macce
#define HAVE_CHARSET_macroman
#define HAVE_CHARSET_sjis 1
/* #undef HAVE_CHARSET_swe7 */
#define HAVE_CHARSET_swe7
#define HAVE_CHARSET_tis620 1
#define HAVE_CHARSET_ucs2 1
#define HAVE_CHARSET_ujis 1
#define HAVE_CHARSET_utf8 1
#define HAVE_UCA_COLLATIONS 1
#define HAVE_BOOL 1

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2000 MySQL AB
/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View file

@ -472,6 +472,7 @@ my_bool my_propagate_complex(CHARSET_INFO *cs, const uchar *str, size_t len);
uint my_string_repertoire(CHARSET_INFO *cs, const char *str, ulong len);
my_bool my_charset_is_ascii_based(CHARSET_INFO *cs);
my_bool my_charset_is_8bit_pure_ascii(CHARSET_INFO *cs);
uint my_charset_repertoire(CHARSET_INFO *cs);
#define _MY_U 01 /* Upper case */

View file

@ -724,7 +724,6 @@ typedef SOCKET_SIZE_TYPE size_socket;
#define UNSINT32 /* unsigned int32 */
/* General constants */
#define SC_MAXWIDTH 256 /* Max width of screen (for error messages) */
#define FN_LEN 256 /* Max file name len */
#define FN_HEADLEN 253 /* Max length of filepart of file name */
#define FN_EXTLEN 20 /* Max length of extension (part of FN_LEN) */
@ -789,6 +788,9 @@ typedef SOCKET_SIZE_TYPE size_socket;
#define ulonglong2double(A) ((double) (ulonglong) (A))
#define my_off_t2double(A) ((double) (my_off_t) (A))
#endif
#ifndef double2ulonglong
#define double2ulonglong(A) ((ulonglong) (double) (A))
#endif
#endif
#ifndef offsetof
@ -1130,6 +1132,9 @@ typedef char bool; /* Ordinary boolean values 0 1 */
#define dbug_volatile
#endif
/* Some helper macros */
#define YESNO(X) ((X) ? "yes" : "no")
/* Defines for time function */
#define SCALE_SEC 100
#define SCALE_USEC 10000

View file

@ -39,8 +39,6 @@ extern int NEAR my_errno; /* Last error in mysys */
#define MYSYS_PROGRAM_DONT_USE_CURSES() { error_handler_hook = my_message_no_curses; mysys_uses_curses=0;}
#define MY_INIT(name); { my_progname= name; my_init(); }
#define ERRMSGSIZE (SC_MAXWIDTH) /* Max length of a error message */
#define NRERRBUFFS (2) /* Buffers for parameters */
#define MY_FILE_ERROR ((size_t) -1)
/* General bitmaps for my_func's */
@ -208,7 +206,6 @@ extern void my_large_free(uchar * ptr, myf my_flags);
extern int errno; /* declare errno */
#endif
#endif /* #ifndef errno */
extern char NEAR errbuff[NRERRBUFFS][ERRMSGSIZE];
extern char *home_dir; /* Home directory for user */
extern const char *my_progname; /* program-name (printed in errors) */
extern char NEAR curr_dir[]; /* Current directory for user */

View file

@ -185,7 +185,7 @@ typedef struct st_mi_keydef /* Key definition with open & info */
uint16 maxlength; /* max length of (packed) key (auto) */
uint16 block_size_index; /* block_size (auto) */
uint32 version; /* For concurrent read/write */
uint32 ftparser_nr; /* distinct ftparser number */
uint32 ftkey_nr; /* full-text index number */
HA_KEYSEG *seg,*end;
struct st_mysql_ftparser *parser; /* Fulltext [pre]parser */

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2000 MySQL AB
/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -159,7 +159,8 @@ void thr_multi_unlock(THR_LOCK_DATA **data,uint count);
void thr_abort_locks(THR_LOCK *lock, my_bool upgrade_lock);
my_bool thr_abort_locks_for_thread(THR_LOCK *lock, my_thread_id thread);
void thr_print_locks(void); /* For debugging */
my_bool thr_upgrade_write_delay_lock(THR_LOCK_DATA *data);
my_bool thr_upgrade_write_delay_lock(THR_LOCK_DATA *data,
enum thr_lock_type new_lock_type);
void thr_downgrade_write_lock(THR_LOCK_DATA *data,
enum thr_lock_type new_lock_type);
my_bool thr_reschedule_write_lock(THR_LOCK_DATA *data);

View file

@ -32,7 +32,7 @@ ADD_EXECUTABLE(mysql_embedded ../../client/completion_hash.cc
TARGET_LINK_LIBRARIES(mysql_embedded debug dbug strings mysys vio yassl taocrypt regex ws2_32)
ADD_DEPENDENCIES(mysql_embedded libmysqld)
ADD_EXECUTABLE(mysqltest_embedded ../../client/mysqltest.c)
ADD_EXECUTABLE(mysqltest_embedded ../../client/mysqltest.cc)
TARGET_LINK_LIBRARIES(mysqltest_embedded debug dbug strings mysys vio yassl taocrypt regex ws2_32)
ADD_DEPENDENCIES(mysqltest_embedded libmysqld)

View file

@ -41,7 +41,7 @@ LDADD = @CLIENT_EXTRA_LDFLAGS@ ../libmysqld.a @LIBDL@ $(CXXLDFLAGS) \
@NDB_SCI_LIBS@
mysqltest_embedded_LINK = $(CXXLINK)
nodist_mysqltest_embedded_SOURCES = mysqltest.c
nodist_mysqltest_embedded_SOURCES = mysqltest.cc
mysqltest_embedded_LDADD = $(LDADD) $(top_builddir)/regex/libregex.a
nodist_mysql_SOURCES = mysql.cc readline.cc completion_hash.cc \

View file

@ -17,132 +17,111 @@
## Process this file with automake to create Makefile.in
SUBDIRS = ndb
testdir = $(prefix)/mysql-test
benchdir_root= $(prefix)
testdir = $(benchdir_root)/mysql-test
EXTRA_SCRIPTS = mysql-test-run-shell.sh install_test_db.sh \
valgrind.supp $(PRESCRIPTS)
EXTRA_DIST = $(EXTRA_SCRIPTS) suite
GENSCRIPTS = mysql-test-run-shell install_test_db mtr mysql-test-run
PRESCRIPTS = mysql-test-run.pl mysql-stress-test.pl
test_SCRIPTS = $(GENSCRIPTS) $(PRESCRIPTS)
CLEANFILES = $(GENSCRIPTS)
test_SCRIPTS = mtr \
mysql-test-run \
mysql-test-run.pl \
mysql-stress-test.pl
INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include -I..
nobase_test_DATA = \
lib/v1/mysql-test-run.pl \
lib/v1/mtr_cases.pl \
lib/v1/mtr_io.pl \
lib/v1/mtr_report.pl \
lib/v1/My/Config.pm \
lib/v1/mtr_gcov.pl \
lib/v1/mtr_match.pl \
lib/v1/mtr_stress.pl \
lib/v1/ndb_config_1_node.ini \
lib/v1/ndb_config_2_node.ini \
lib/v1/mtr_gprof.pl \
lib/v1/mtr_misc.pl \
lib/v1/mtr_timer.pl \
lib/v1/mtr_im.pl \
lib/v1/mtr_process.pl \
lib/v1/mtr_unique.pl \
\
lib/mtr_cases.pm \
lib/mtr_gcov.pl \
lib/mtr_gprof.pl \
lib/mtr_io.pl \
lib/mtr_match.pm \
lib/mtr_misc.pl \
lib/mtr_process.pl \
lib/mtr_report.pm \
lib/mtr_stress.pl \
lib/mtr_unique.pm \
lib/My/ConfigFactory.pm \
lib/My/Config.pm \
lib/My/Find.pm \
lib/My/Handles.pm \
lib/My/Options.pm \
lib/My/Test.pm \
lib/My/Platform.pm \
lib/My/SafeProcess.pm \
lib/My/File/Path.pm \
lib/My/SysInfo.pm \
lib/My/CoreDump.pm \
lib/My/SafeProcess/Base.pm \
lib/My/SafeProcess/safe_process.pl
SUBDIRS = lib/My/SafeProcess
EXTRA_DIST = README \
valgrind.supp \
$(test_SCRIPTS) \
$(nobase_test_DATA)
# List of directories containing test + result files and the
# related test data files that should be copied
TEST_DIRS = t r include std_data std_data/parts \
std_data/ndb_backup50 std_data/ndb_backup51 \
std_data/ndb_backup51_data_be std_data/ndb_backup51_data_le \
std_data/funcs_1 \
extra/binlog_tests/ extra/rpl_tests \
suite/binlog suite/binlog/t suite/binlog/r suite/binlog/std_data \
suite/bugs/data suite/bugs/t suite/bugs/r \
suite/federated \
suite/funcs_1 suite/funcs_1/bitdata \
suite/funcs_1/include suite/funcs_1/lib suite/funcs_1/r \
suite/funcs_1/t suite/funcs_1/views suite/funcs_1/cursors \
suite/funcs_1/datadict suite/funcs_1/storedproc suite/funcs_1/triggers \
suite/funcs_2 suite/funcs_2/charset suite/funcs_2/data \
suite/funcs_2/include suite/funcs_2/lib suite/funcs_2/r \
suite/funcs_2/t \
suite/jp suite/jp/t suite/jp/r suite/jp/std_data \
suite/manual/t suite/manual/r \
suite/ndb_team suite/ndb_team/t suite/ndb_team/r \
suite/rpl suite/rpl/data suite/rpl/include suite/rpl/r \
suite/rpl/t \
suite/stress/include suite/stress/t suite/stress/r \
suite/ndb suite/ndb/t suite/ndb/r \
suite/rpl_ndb suite/rpl_ndb/t suite/rpl_ndb/r \
suite/parts suite/parts/t suite/parts/r suite/parts/inc
# Used by dist-hook and install-data-local to copy all
# test files into either dist or install directory
install_test_files:
@if test -z "$(INSTALL_TO_DIR)"; then \
echo "Set INSTALL_TO_DIR!" && exit 1; \
fi
@for dir in $(TEST_DIRS); do \
from_dir="$(srcdir)/$$dir"; \
to_dir="$(INSTALL_TO_DIR)/$$dir"; \
$(mkinstalldirs) "$$to_dir"; \
for f in `(cd $$from_dir && ls)`; do \
if test -f "$$from_dir/$$f"; then \
$(INSTALL_DATA) "$$from_dir/$$f" "$$to_dir/$$f" ; \
fi; \
done \
done
dist-hook:
mkdir -p \
$(distdir)/t \
$(distdir)/extra/binlog_tests \
$(distdir)/extra/rpl_tests \
$(distdir)/r \
$(distdir)/include \
$(distdir)/std_data \
$(distdir)/std_data/ndb_backup50 \
$(distdir)/std_data/ndb_backup51 \
$(distdir)/std_data/ndb_backup51_data_be \
$(distdir)/std_data/ndb_backup51_data_le \
$(distdir)/std_data/parts \
$(distdir)/lib \
$(distdir)/std_data/funcs_1 \
$(distdir)/lib/My
-$(INSTALL_DATA) $(srcdir)/t/*.def $(distdir)/t
$(INSTALL_DATA) $(srcdir)/t/*.test $(distdir)/t
-$(INSTALL_DATA) $(srcdir)/t/*.imtest $(distdir)/t
$(INSTALL_DATA) $(srcdir)/t/*.sql $(distdir)/t
-$(INSTALL_DATA) $(srcdir)/t/*.disabled $(distdir)/t
-$(INSTALL_DATA) $(srcdir)/t/*.opt $(srcdir)/t/*.slave-mi $(distdir)/t
-$(INSTALL_SCRIPT) $(srcdir)/t/*.sh $(distdir)/t
$(INSTALL_DATA) $(srcdir)/extra/binlog_tests/*.test $(distdir)/extra/binlog_tests
$(INSTALL_DATA) $(srcdir)/extra/rpl_tests/*.test $(distdir)/extra/rpl_tests
-$(INSTALL_DATA) $(srcdir)/extra/binlog_tests/*.opt $(distdir)/extra/binlog_tests
-$(INSTALL_DATA) $(srcdir)/extra/rpl_tests/*.opt $(distdir)/extra/rpl_tests
$(INSTALL_DATA) $(srcdir)/include/*.inc $(distdir)/include
$(INSTALL_DATA) $(srcdir)/include/*.sql $(distdir)/include
$(INSTALL_DATA) $(srcdir)/include/*.test $(distdir)/include
$(INSTALL_DATA) $(srcdir)/r/*.result $(srcdir)/r/*.require $(distdir)/r
$(INSTALL_DATA) $(srcdir)/std_data/Moscow_leap $(distdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/Index.xml $(distdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/*.dat $(srcdir)/std_data/*.000001 $(distdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/des_key_file $(distdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/*.pem $(distdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/*.frm $(distdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/*.MY* $(distdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/*.cnf $(distdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/*.txt $(distdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/ndb_backup50/BACKUP* $(distdir)/std_data/ndb_backup50
$(INSTALL_DATA) $(srcdir)/std_data/ndb_backup51/BACKUP* $(distdir)/std_data/ndb_backup51
$(INSTALL_DATA) $(srcdir)/std_data/ndb_backup51_data_be/BACKUP* $(distdir)/std_data/ndb_backup51_data_be
$(INSTALL_DATA) $(srcdir)/std_data/ndb_backup51_data_le/BACKUP* $(distdir)/std_data/ndb_backup51_data_le
$(INSTALL_DATA) $(srcdir)/std_data/parts/part_* $(distdir)/std_data/parts
$(INSTALL_DATA) $(srcdir)/std_data/parts/*.MY* $(distdir)/std_data/parts
$(INSTALL_DATA) $(srcdir)/std_data/funcs_1/* $(distdir)/std_data/funcs_1
$(INSTALL_DATA) $(srcdir)/lib/*.pl $(distdir)/lib
$(INSTALL_DATA) $(srcdir)/lib/My/*.pm $(distdir)/lib/My
-rm -rf `find $(distdir)/suite -type d -name SCCS` $(distdir)/suite/row_lock
$(MAKE) INSTALL_TO_DIR="$(distdir)" install_test_files
install-data-local:
$(mkinstalldirs) \
$(DESTDIR)$(testdir)/t \
$(DESTDIR)$(testdir)/extra/binlog_tests \
$(DESTDIR)$(testdir)/extra/rpl_tests \
$(DESTDIR)$(testdir)/r \
$(DESTDIR)$(testdir)/include \
$(DESTDIR)$(testdir)/std_data \
$(DESTDIR)$(testdir)/std_data/ndb_backup50 \
$(DESTDIR)$(testdir)/std_data/ndb_backup51 \
$(DESTDIR)$(testdir)/std_data/ndb_backup51_data_be \
$(DESTDIR)$(testdir)/std_data/ndb_backup51_data_le \
$(DESTDIR)$(testdir)/std_data/parts \
$(DESTDIR)$(testdir)/lib \
$(DESTDIR)$(testdir)/std_data/funcs_1 \
$(DESTDIR)$(testdir)/lib/My
$(INSTALL_DATA) $(srcdir)/README $(DESTDIR)$(testdir)
-$(INSTALL_DATA) $(srcdir)/t/*.def $(DESTDIR)$(testdir)/t
$(INSTALL_DATA) $(srcdir)/t/*.test $(DESTDIR)$(testdir)/t
-$(INSTALL_DATA) $(srcdir)/t/*.imtest $(DESTDIR)$(testdir)/t
$(INSTALL_DATA) $(srcdir)/t/*.sql $(DESTDIR)$(testdir)/t
-$(INSTALL_DATA) $(srcdir)/t/*.disabled $(DESTDIR)$(testdir)/t
-$(INSTALL_DATA) $(srcdir)/t/*.opt $(DESTDIR)$(testdir)/t
-$(INSTALL_SCRIPT) $(srcdir)/t/*.sh $(DESTDIR)$(testdir)/t
-$(INSTALL_DATA) $(srcdir)/t/*.slave-mi $(DESTDIR)$(testdir)/t
$(INSTALL_DATA) $(srcdir)/r/*.result $(DESTDIR)$(testdir)/r
$(INSTALL_DATA) $(srcdir)/r/*.require $(DESTDIR)$(testdir)/r
$(INSTALL_DATA) $(srcdir)/extra/binlog_tests/*.test $(DESTDIR)$(testdir)/extra/binlog_tests
$(INSTALL_DATA) $(srcdir)/extra/rpl_tests/*.test $(DESTDIR)$(testdir)/extra/rpl_tests
-$(INSTALL_DATA) $(srcdir)/extra/binlog_tests/*.opt $(DESTDIR)$(testdir)/extra/binlog_tests
-$(INSTALL_DATA) $(srcdir)/extra/rpl_tests/*.opt $(DESTDIR)$(testdir)/extra/rpl_tests
$(INSTALL_DATA) $(srcdir)/include/*.inc $(DESTDIR)$(testdir)/include
$(INSTALL_DATA) $(srcdir)/include/*.sql $(DESTDIR)$(testdir)/include
$(INSTALL_DATA) $(srcdir)/include/*.test $(DESTDIR)$(testdir)/include
$(INSTALL_DATA) $(srcdir)/std_data/*.dat $(DESTDIR)$(testdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/*.*001 $(DESTDIR)$(testdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/*.cnf $(DESTDIR)$(testdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/des_key_file $(DESTDIR)$(testdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/Moscow_leap $(DESTDIR)$(testdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/Index.xml $(DESTDIR)$(testdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/*.pem $(DESTDIR)$(testdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/*.frm $(DESTDIR)$(testdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/*.MY* $(DESTDIR)$(testdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/*.cnf $(DESTDIR)$(testdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/*.txt $(DESTDIR)$(testdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/ndb_backup50/BACKUP* $(DESTDIR)$(testdir)/std_data/ndb_backup50
$(INSTALL_DATA) $(srcdir)/std_data/ndb_backup51/BACKUP* $(DESTDIR)$(testdir)/std_data/ndb_backup51
$(INSTALL_DATA) $(srcdir)/std_data/ndb_backup51_data_be/BACKUP* $(DESTDIR)$(testdir)/std_data/ndb_backup51_data_be
$(INSTALL_DATA) $(srcdir)/std_data/ndb_backup51_data_le/BACKUP* $(DESTDIR)$(testdir)/std_data/ndb_backup51_data_le
$(INSTALL_DATA) $(srcdir)/std_data/parts/part_* $(DESTDIR)$(testdir)/std_data/parts
$(INSTALL_DATA) $(srcdir)/std_data/parts/*.MY* $(DESTDIR)$(testdir)/std_data/parts
$(INSTALL_DATA) $(srcdir)/std_data/funcs_1/* $(DESTDIR)$(testdir)/std_data/funcs_1
$(INSTALL_DATA) $(srcdir)/lib/*.pl $(DESTDIR)$(testdir)/lib
$(INSTALL_DATA) $(srcdir)/lib/My/*.pm $(DESTDIR)$(testdir)/lib/My
for f in `(cd $(srcdir); find suite -type f | egrep -v 'SCCS|row_lock')`; \
do \
d=$(DESTDIR)$(testdir)/`dirname $$f`; \
mkdir -p $$d ; \
$(INSTALL_DATA) $(srcdir)/$$f $$d ; \
done
$(MAKE) INSTALL_TO_DIR="$(DESTDIR)$(testdir)" install_test_files
uninstall-local:
@RM@ -f -r $(DESTDIR)$(testdir)
@ -157,31 +136,5 @@ mysql-test-run:
$(RM) -f mysql-test-run
$(LN_S) mysql-test-run.pl mysql-test-run
SUFFIXES = .sh
.sh:
@RM@ -f $@ $@-t
@SED@ \
-e 's!@''testdir''@!$(testdir)!g' \
-e 's!@''bindir''@!$(bindir)!g' \
-e 's!@''scriptdir''@!$(bindir)!g' \
-e 's!@''prefix''@!$(prefix)!g' \
-e 's!@''datadir''@!$(datadir)!g' \
-e 's!@''localstatedir''@!$(localstatedir)!g' \
-e 's!@''libexecdir''@!$(libexecdir)!g' \
-e 's!@''PERL''@!@PERL@!' \
-e 's!@''VERSION''@!@VERSION@!' \
-e 's!@''MYSQL_TCP_PORT''@!@MYSQL_TCP_PORT@!' \
-e 's!@''MYSQL_TCP_PORT_DEFAULT''@!@MYSQL_TCP_PORT_DEFAULT@!' \
-e 's!@''MYSQL_BASE_VERSION''@!@MYSQL_BASE_VERSION@!' \
-e 's!@''MYSQL_UNIX_ADDR''@!@MYSQL_UNIX_ADDR@!' \
-e 's!@''MYSQL_TCP_PORT''@!@MYSQL_TCP_PORT@!' \
-e 's!@''MYSQL_NO_DASH_VERSION''@!@MYSQL_NO_DASH_VERSION@!' \
-e 's!@''MYSQL_SERVER_SUFFIX''@!@MYSQL_SERVER_SUFFIX@!' \
-e 's!@''USE_NDBCLUSTER''@!@TEST_NDBCLUSTER@!g' \
$< > $@-t
@CHMOD@ +x $@-t
@MV@ $@-t $@
# Don't update the files from bitkeeper
%::SCCS/s.%

View file

@ -1,65 +0,0 @@
#! /bin/sh
# This script is a hack for lazy developers who want to get a quick
# start on the result file. The code here is rather dirty, but it works
# If you have a spare moment feel free to improve it - the right way is
# to start mysqld yourself and run mysqltest -r
RESULT_DIR=r
if [ -z "$EDITOR" ] ; then
EDITOR=vi
fi
function die()
{
echo $1
exit 1
}
function usage()
{
echo "Usage: $0 test_name"
exit 1
}
test_name=$1
[ -z "$test_name" ] && usage
result_file=$RESULT_DIR/$test_name.result
reject_file=$RESULT_DIR/$test_name.reject
[ -f $result_file ] && die "result file $result_file has already been created"
touch $result_file
echo "Running the test case against empty file, will fail, but don't worry"
./mysql-test-run --local $test_name
if [ -f $reject_file ] ; then
echo "Below are the contents of the reject file:"
echo "-----start---------------------"
cat $reject_file
echo "-----end-----------------------"
echo "Is this the output you expected from your test case?(y/n)[n]"
read yes_no
if [ x$yes_no = xy ] ; then
echo "Press any key to edit it in $EDITOR, or Ctrl-C to abort"
read junk
$EDITOR $reject_file
edited="edited"
fi
echo "Save $edited file as master result? (y/n)[y]"
read yes_no
if [ x$yes_no != xn ]; then
mv $reject_file $result_file
fi
else
echo "Your test failed so bad, it did not even produce a reject file"
echo "You need to fix your bugs in the test case, the code, or both"
exit 1
fi

View file

@ -0,0 +1,27 @@
# BUG #36763: TRUNCATE TABLE fails to replicate when stmt-based
# binlogging is not supported.
# This should always be logged as a statement, even when executed as a
# row-by-row deletion.
# $before_truncate A statement to execute (just) before issuing the
# TRUNCATE TABLE
eval CREATE TABLE t1 (a INT) ENGINE=$engine;
eval CREATE TABLE t2 (a INT) ENGINE=$engine;
INSERT INTO t2 VALUES (1),(2),(3);
let $binlog_start = query_get_value("SHOW MASTER STATUS", Position, 1);
if (`select length('$before_truncate') > 0`) {
eval $before_truncate;
}
--echo **** Truncate of empty table shall be logged
TRUNCATE TABLE t1;
if (`select length('$before_truncate') > 0`) {
eval $before_truncate;
}
TRUNCATE TABLE t2;
source include/show_binlog_events.inc;
DROP TABLE t1,t2;

View file

@ -7,7 +7,7 @@
-- source include/have_log_bin.inc
# The server need to be started in $MYSQLTEST_VARDIR since it
# uses ../std_data_ln/
# uses ../../std_data/
-- source include/uses_vardir.inc
--disable_warnings
@ -114,7 +114,7 @@ insert into t1 values(1);
insert ignore into t1 values(1);
replace into t1 values(100);
create table t2 (a varchar(200)) engine=blackhole;
eval load data infile '../std_data_ln/words.dat' into table t2;
eval load data infile '../../std_data/words.dat' into table t2;
alter table t1 add b int;
alter table t1 drop b;
create table t3 like t1;

View file

@ -16,7 +16,8 @@ source include/show_binlog_events.inc;
# escaped).
flush logs;
--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
--exec $MYSQL_BINLOG --short-form $MYSQLTEST_VARDIR/log/master-bin.000001
let $MYSQLD_DATADIR= `select @@datadir`;
--exec $MYSQL_BINLOG --short-form $MYSQLD_DATADIR/master-bin.000001
drop table t2;
# End of 4.1 tests

View file

@ -28,3 +28,5 @@ enable_warnings;
insert into t1 values (1);
drop table tt1, t1;
source include/show_binlog_events.inc;
FLUSH STATUS;

View file

@ -317,17 +317,18 @@ connection con4;
select get_lock("a",10); # wait for rollback to finish
flush logs;
let $MYSQLD_DATADIR= `select @@datadir`;
# we check that the error code of the "ROLLBACK" event is 0 and not
# ER_SERVER_SHUTDOWN (i.e. disconnection just rolls back transaction
# and does not make slave to stop)
if (`select @@binlog_format = 'ROW'`)
{
--exec $MYSQL_BINLOG --start-position=524 $MYSQLTEST_VARDIR/log/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/mix_innodb_myisam_binlog.output
--exec $MYSQL_BINLOG --start-position=524 $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/mix_innodb_myisam_binlog.output
}
if (`select @@binlog_format = 'STATEMENT' || @@binlog_format = 'MIXED'`)
{
--exec $MYSQL_BINLOG --start-position=555 $MYSQLTEST_VARDIR/log/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/mix_innodb_myisam_binlog.output
--exec $MYSQL_BINLOG --start-position=555 $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/mix_innodb_myisam_binlog.output
}
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
@ -618,7 +619,7 @@ CREATE TABLE t5 (a int, PRIMARY KEY (a)) ENGINE=InnoDB;
# execute
--error ER_DUP_ENTRY
load data infile '../std_data_ln/rpl_loaddata.dat' into table t4 (a, @b) set b= @b + bug27417(2);
load data infile '../../std_data/rpl_loaddata.dat' into table t4 (a, @b) set b= @b + bug27417(2);
# check
select * from t4;
select count(*) from t1 /* must be 2 */;

View file

@ -278,7 +278,7 @@ CREATE TABLE t5 (a int, PRIMARY KEY (a)) ENGINE=InnoDB;
# execute
--error ER_DUP_ENTRY
load data infile '../std_data_ln/rpl_loaddata.dat' into table t4 (a, @b) set b= @b + bug27417(2);
load data infile '../../std_data/rpl_loaddata.dat' into table t4 (a, @b) set b= @b + bug27417(2);
# check
select * from t4;
select count(*) from t1 /* must be 2 */;

View file

@ -20,7 +20,8 @@
eval create table t1 (a int) engine=$engine_type;
flush tables;
remove_file $MYSQLTEST_VARDIR/master-data/test/t1.MYI ;
let $MYSQLD_DATADIR= `select @@datadir`;
remove_file $MYSQLD_DATADIR/test/t1.MYI ;
drop table if exists t1;
save_master_pos;
connection slave;

View file

@ -145,6 +145,23 @@ select * from t3 order by a;
connection master;
drop table t1,t2,t3;
sync_slave_with_master;
#
# BUG#41986 Replication slave does not pick up proper AUTO_INCREMENT value for Innodb tables
#
connection master;
set auto_increment_increment=1;
set auto_increment_offset=1;
CREATE TABLE t1 (id MEDIUMINT NOT NULL AUTO_INCREMENT PRIMARY KEY) ENGINE=innodb;
INSERT INTO t1 VALUES (NULL), (NULL), (NULL);
show create table t1;
sync_slave_with_master;
show create table t1;
connection master;
drop table t1;
# End cleanup
sync_slave_with_master;

View file

@ -0,0 +1,168 @@
# ==== Purpose ====
#
# Test that slave behaves well in some conflict situations. The
# following are tested:
#
# - The slave SQL thread sees an 'INSERT' of a row with a key that
# already exists in the table;
#
# - The slave SQL thread sees a 'DELETE' of a row that does not
# exist in the table.
#
# In statement-logging mode, the first conflict type causes the slave
# to stop with an error and the second conflict is ignored.
#
# In row-logging mode, the slave behavior depends the value of
# @@slave_exec_mode on the slave: if @@slave_exec_mode is IDEMPOTENT,
# the slave should ignore the conflicting statement and continue
# normally. If @@slave_exec_mode is STRICT, the slave should stop
# with an error.
#
# This test was previously named rpl_stm_mystery22/rpl_row_mystery22.
#
#
# ==== Method ====
#
# Create a table on master and slave, insert a row on slave, and
# insert the same row on master.
#
# Create a table on master and slave, insert a row on master with
# binlogging turned off, and remove the row on master with binlogging
# turned on.
#
#
# ==== Related bugs ====
#
# BUG#31552: Replication breaks when deleting rows from out-of-sync table without PK
# BUG#31609: Not all RBR slave errors reported as errors
#
# Bug in this test case:
# BUG#37718: rpl.rpl_stm_mystery22 fails sporadically on pushbuild
#
#
# ==== Usage ====
#
# This file assumes the following:
#
# - The test language variable $slave_is_idempotent is set to 1 if the
# slave is expected to stop on duplicate key errors (i.e., if the
# binlog is in statement mode or
# @@global.slave_exec_mode=STRICT). It is set to 0 otherwise.
#
# - Replication has been initialized by include/master-slave.inc
#
# - The test adds a suppression for the following warning:
# Slave: Can't find record in 't1' Error_code: 1032
--echo ==== Initialize ====
--echo [on master]
connection master;
CREATE TABLE t1(a INT PRIMARY KEY);
--echo [on slave]
sync_slave_with_master;
--echo ==== Test: SQL thread sees 'INSERT' of existing key ====
--echo ---- Prepare slave so that it will get duplicate key error ----
# This row will be in the way of the row inserted by master.
INSERT INTO t1 VALUES (1);
--echo ---- Insert rows on master ----
--echo [on master]
connection master;
# Insert the same row on master
INSERT INTO t1 VALUES (1);
save_master_pos;
SELECT * FROM t1;
--echo [on slave]
connection slave;
# If we are statement-logging or if slave_exec_mode=STRICT, we now
# expect to see an error on the slave. Otherwise (i.e., we are
# row-logging and slave_exec_mode=IDEMPOTENT), we expect that the
# duplicate row is ignored by the slave and replication continues.
if (`SELECT @@global.binlog_format != 'ROW' OR @@global.slave_exec_mode = 'STRICT'`) {
--echo ---- Wait until slave stops with an error ----
# Wait until the slave tries to run the query, fails with duplicate
# key error, and stops the SQL thread.
let $slave_sql_errno= 1062; # ER_DUP_ENTRY
source include/wait_for_slave_sql_error.inc;
let $err= query_get_value("SHOW SLAVE STATUS", Last_SQL_Error, 1);
--echo Last_SQL_Error = $err (expected "duplicate key" error)
SELECT * FROM t1;
--echo ---- Resolve the conflict on the slave and restart SQL thread ----
DELETE FROM t1 WHERE a = 1;
START SLAVE SQL_THREAD;
source include/wait_for_slave_sql_to_start.inc;
}
--echo ---- Sync slave and verify that there is no error ----
sync_with_master;
let $err= query_get_value("SHOW SLAVE STATUS", Last_SQL_Error, 1);
--echo Last_SQL_Error = '$err' (expected no error)
SELECT * FROM t1;
--echo ==== Test: SQL thread sees 'DELETE' of non-existing row ====
--echo ---- On master, insert two rows, the second with binlogging off ----
--echo [on master]
connection master;
DELETE FROM t1;
INSERT INTO t1 VALUES (1);
--echo [on slave]
sync_slave_with_master;
DELETE FROM t1 WHERE a = 1;
--echo ---- On master, remove the row that does not exist on slave ----
--echo [on master]
connection master;
DELETE FROM t1 WHERE a = 1;
SELECT * FROM t1;
save_master_pos;
--echo [on slave]
connection slave;
# If we are row-logging and slave_exec_mode is STRICT, we now expect
# an error since the row to delete does not exist on slave. Otherwise
# (i.e., either we are statement-logging or slave_exec_mode is
# IDEMPOTENT), the absence of the row to delete is ignored and
# replication continues.
if (`SELECT @@global.binlog_format = 'ROW' AND @@global.slave_exec_mode = 'STRICT'`) {
--echo ---- Wait until slave stops with an error ----
let $slave_sql_errno= 1032; # ER_KEY_NOT_FOUND
source include/wait_for_slave_sql_error.inc;
let $err= query_get_value("SHOW SLAVE STATUS", Last_SQL_Error, 1);
--echo Last_SQL_Error = $err (expected "can't find record" error)
SELECT * FROM t1;
--echo ---- Resolve the conflict on the slave and restart SQL thread ----
INSERT INTO t1 VALUES (1);
START SLAVE SQL_THREAD;
source include/wait_for_slave_sql_to_start.inc;
}
--echo ---- Sync slave and verify that there is no error ----
# The slave should sync ok, and SHOW SLAVE STATUS should give no
# error.
sync_with_master;
let $err= query_get_value("SHOW SLAVE STATUS", Last_SQL_Error, 1);
--echo Last_SQL_Error = $err (expected no error)
SELECT * FROM t1;
--echo ==== Clean up ====
--echo [on master]
connection master;
DROP TABLE t1;
--echo [on slave]
sync_slave_with_master;

View file

@ -419,7 +419,7 @@ connection master;
update t31 set f5=555555555555555 where f3=6;
update t31 set f2=2 where f3=2;
update t31 set f1=NULL where f3=1;
update t31 set f3=0, f27=NULL, f35='f35 new value' where f3=3;
update t31 set f3=NULL, f27=NULL, f35='f35 new value' where f3=3;
--echo
--echo ** Delete from Master **
@ -497,7 +497,7 @@ INSERT INTO t10 () VALUES(1,@b1,DEFAULT,'Kyle',DEFAULT),
--echo ********************************************
--echo
connection slave;
wait_for_slave_to_stop;
source include/wait_for_slave_sql_to_stop.inc;
--replace_result $MASTER_MYPORT MASTER_PORT
--replace_column 1 # 4 # 7 # 8 # 9 # 22 # 23 # 33 # 35 # 36 #
--query_vertical SHOW SLAVE STATUS
@ -554,7 +554,7 @@ INSERT INTO t11 () VALUES(1,@b1,'Testing is fun','Kyle',DEFAULT),
--echo ********************************************
--echo
connection slave;
wait_for_slave_to_stop;
source include/wait_for_slave_sql_to_stop.inc;
--replace_result $MASTER_MYPORT MASTER_PORT
--replace_column 1 # 4 # 7 # 8 # 9 # 22 # 23 # 33 # 35 # 36 #
--query_vertical SHOW SLAVE STATUS
@ -697,7 +697,7 @@ SELECT c1,c3,hex(c4),c5,c6 FROM t14 ORDER BY c1;
# Remove below once fixed
#***************************
connection slave;
wait_for_slave_to_stop;
source include/wait_for_slave_sql_to_stop.inc;
--replace_result $MASTER_MYPORT MASTER_PORT
--replace_column 1 # 4 # 7 # 8 # 9 # 22 # 23 # 33 # 35 # 36 #
--query_vertical SHOW SLAVE STATUS
@ -763,7 +763,7 @@ SELECT c1,hex(c4),c5,c6,c7,c2 FROM t15 ORDER BY c1;
--echo ********************************************
--echo
connection slave;
wait_for_slave_to_stop;
source include/wait_for_slave_sql_to_stop.inc;
--replace_result $MASTER_MYPORT MASTER_PORT
--replace_column 1 # 4 # 7 # 8 # 9 # 22 # 23 # 33 # 35 # 36 #
--query_vertical SHOW SLAVE STATUS
@ -840,7 +840,7 @@ SELECT c1,hex(c4),c5,c6,c7 FROM t16 ORDER BY c1;
--echo *****************
--echo
connection slave;
wait_for_slave_to_stop;
source include/wait_for_slave_sql_to_stop.inc;
--replace_result $MASTER_MYPORT MASTER_PORT
--replace_column 1 # 4 # 7 # 8 # 9 # 22 # 23 # 33 # 35 # 36 #
--query_vertical SHOW SLAVE STATUS

View file

@ -94,7 +94,7 @@ SELECT * FROM t2 ORDER BY a;
--echo *** Start Slave ***
connection slave;
START SLAVE;
wait_for_slave_to_stop;
source include/wait_for_slave_sql_to_stop.inc;
--replace_result $MASTER_MYPORT MASTER_PORT
--replace_column 1 # 4 # 7 # 8 # 9 # 16 # 22 # 23 # 33 # 35 # 36 #
--query_vertical SHOW SLAVE STATUS
@ -429,6 +429,7 @@ set @b1 = 'b1b1b1b1';
set @b1 = concat(@b1,@b1);
INSERT INTO t9 () VALUES(1,@b1,'Kyle'),(2,@b1,'JOE'),(3,@b1,'QA');
connection slave;
--source include/wait_for_slave_sql_to_stop.inc
--replace_result $MASTER_MYPORT MASTER_PORT
--replace_column 1 # 4 # 7 # 8 # 9 # 16 # 22 # 23 # 33 # 35 # 36 #

View file

@ -4,8 +4,7 @@
# Test of FLUSH NO_WRITE_TO_BINLOG by the way.
#
-- source include/master-slave.inc
source include/master-slave.inc;
let $SERVER_VERSION=`select version()`;
@ -34,26 +33,32 @@ flush tables;
--replace_column 2 # 5 #
--replace_regex /table_id: [0-9]+/table_id: #/
eval SHOW BINLOG EVENTS FROM $rename_event_pos ;
save_master_pos;
connection slave;
sync_with_master;
sync_slave_with_master;
# Check that the slave is not confused.
select * from t3;
# Note that all this confusion may cause warnings 'table xx is open on rename'
# in the .err files; these are not fatal and are not reported by mysql-test-run.
stop slave;
source include/wait_for_slave_to_stop.inc;
connection master;
drop table t1;
connection slave;
flush tables with read lock;
start slave;
sleep 1;
source include/wait_for_slave_to_start.inc;
--error 1192
stop slave;
# Cleanup
unlock tables;
connection master;
drop table t3, t4, t5;
sync_slave_with_master;
# End of 4.1 tests

View file

@ -23,12 +23,12 @@ connection master;
select last_insert_id();
create table t1(a int not null auto_increment, b int, primary key(a) );
load data infile '../std_data_ln/rpl_loaddata.dat' into table t1;
load data infile '../../std_data/rpl_loaddata.dat' into table t1;
# verify that LAST_INSERT_ID() is set by LOAD DATA INFILE
select last_insert_id();
create temporary table t2 (day date,id int(9),category enum('a','b','c'),name varchar(60));
load data infile '../std_data_ln/rpl_loaddata2.dat' into table t2 fields terminated by ',' optionally enclosed by '%' escaped by '@' lines terminated by '\n##\n' starting by '>' ignore 1 lines;
load data infile '../../std_data/rpl_loaddata2.dat' into table t2 fields terminated by ',' optionally enclosed by '%' escaped by '@' lines terminated by '\n##\n' starting by '>' ignore 1 lines;
create table t3 (day date,id int(9),category enum('a','b','c'),name varchar(60));
insert into t3 select * from t2;
@ -56,7 +56,7 @@ sync_with_master;
insert into t1 values(1,10);
connection master;
load data infile '../std_data_ln/rpl_loaddata.dat' into table t1;
load data infile '../../std_data/rpl_loaddata.dat' into table t1;
save_master_pos;
connection slave;
@ -80,7 +80,7 @@ connection master;
set sql_log_bin=0;
delete from t1;
set sql_log_bin=1;
load data infile '../std_data_ln/rpl_loaddata.dat' into table t1;
load data infile '../../std_data/rpl_loaddata.dat' into table t1;
save_master_pos;
connection slave;
# The SQL slave thread should be stopped now.
@ -105,7 +105,7 @@ connection master;
set sql_log_bin=0;
delete from t1;
set sql_log_bin=1;
load data infile '../std_data_ln/rpl_loaddata.dat' into table t1;
load data infile '../../std_data/rpl_loaddata.dat' into table t1;
save_master_pos;
connection slave;
# The SQL slave thread should be stopped now.
@ -125,7 +125,7 @@ reset master;
eval create table t2 (day date,id int(9),category enum('a','b','c'),name varchar(60),
unique(day)) engine=$engine_type; # no transactions
--error ER_DUP_ENTRY
load data infile '../std_data_ln/rpl_loaddata2.dat' into table t2 fields
load data infile '../../std_data/rpl_loaddata2.dat' into table t2 fields
terminated by ',' optionally enclosed by '%' escaped by '@' lines terminated by
'\n##\n' starting by '>' ignore 1 lines;
select * from t2;
@ -141,24 +141,21 @@ alter table t2 drop key day;
connection master;
delete from t2;
--error ER_DUP_ENTRY
load data infile '../std_data_ln/rpl_loaddata2.dat' into table t2 fields
load data infile '../../std_data/rpl_loaddata2.dat' into table t2 fields
terminated by ',' optionally enclosed by '%' escaped by '@' lines terminated by
'\n##\n' starting by '>' ignore 1 lines;
connection slave;
--source include/wait_for_slave_sql_to_stop.inc
drop table t2;
drop table t1, t2;
connection master;
drop table t2;
drop table t1;
drop table t1, t2;
# BUG#17233 LOAD DATA INFILE: failure causes mysqld dbug_assert, binlog not flushed
CREATE TABLE t1 (word CHAR(20) NOT NULL PRIMARY KEY) ENGINE=INNODB;
--error ER_DUP_ENTRY
LOAD DATA INFILE "../std_data_ln/words.dat" INTO TABLE t1;
LOAD DATA INFILE "../../std_data/words.dat" INTO TABLE t1;
--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
# End of 4.1 tests

View file

@ -9,10 +9,8 @@
# test the slave immediately writes DROP TEMPORARY TABLE this_old_table).
# We wait for the slave to have written all he wants to the binlog
# (otherwise RESET MASTER may come too early).
save_master_pos;
connection slave;
sync_with_master;
stop slave;
sync_slave_with_master;
source include/stop_slave.inc;
--source include/wait_for_slave_to_stop.inc
reset master;
reset slave;
@ -25,8 +23,13 @@ connection master;
eval create table t1(n int not null auto_increment primary key)ENGINE=$engine_type;
insert into t1 values (NULL);
drop table t1;
let $LOAD_FILE= ../../std_data/words.dat;
if (!`SELECT length(load_file('$LOAD_FILE'))`){
let $LOAD_FILE= ../$LOAD_FILE;
}
eval create table t1 (word char(20) not null)ENGINE=$engine_type;
load data infile '../std_data_ln/words.dat' into table t1 ignore 1 lines;
--replace_result $LOAD_FILE LOAD_FILE
eval load data infile '$LOAD_FILE' into table t1 ignore 1 lines;
select count(*) from t1;
--replace_result $VERSION VERSION
--replace_column 2 # 5 #
@ -67,19 +70,13 @@ eval create table t3 (a int)ENGINE=$engine_type;
connection master;
select * from t1 order by 1 asc;
save_master_pos;
connection slave;
# Note that the above 'slave start' will cause a 3rd rotate event (a fake one)
# to go into the relay log (the master always sends a fake one when replication
# starts).
let $result_pattern= '%127.0.0.1%root%master-bin.000002%slave-relay-bin.000005%Yes%Yes%0%0%None%';
--source include/wait_slave_status.inc
sync_with_master;
sync_slave_with_master;
#check t1 on slave to ensure whether it's identical with on master
select * from t1 order by 1 asc;
flush logs;
stop slave;
--source include/wait_for_slave_to_stop.inc
source include/stop_slave.inc;
source include/start_slave.inc;
connection master;
# Create some entries for second log
@ -92,12 +89,11 @@ source include/show_binlog_events.inc;
--replace_column 2 # 5 #
--replace_regex /\/\* xid=.* \*\//\/* XID *\// /table_id: [0-9]+/table_id: #/
show binlog events in 'master-bin.000002';
--replace_column 2 #
show binary logs;
save_master_pos;
connection slave;
start slave;
sync_slave_with_master;
--source include/wait_for_slave_to_start.inc
sync_with_master;
--replace_column 2 #
show binary logs;
--replace_result $MASTER_MYPORT MASTER_PORT $VERSION VERSION
--replace_column 2 # 5 #
@ -133,9 +129,13 @@ DROP TABLE t3;
# Bug #6880: LAST_INSERT_ID() within a statement
#
# Reset binlog so that show binlog events will not show the tests
# above.
source include/master-slave-reset.inc;
connection master;
create table t1(a int auto_increment primary key, b int);
insert into t1 values (NULL, 1);
reset master;
set insert_id=5;
insert into t1 values (NULL, last_insert_id()), (NULL, last_insert_id());
source include/show_binlog_events.inc;
@ -145,4 +145,3 @@ drop table t1;
# End of 4.1 tests
sync_slave_with_master;

Some files were not shown because too many files have changed in this diff Show more