aboutsummaryrefslogtreecommitdiffstats
path: root/lib/sh
diff options
context:
space:
mode:
authorJari Aalto <jari.aalto@cante.net>2000-03-17 21:46:59 +0000
committerJari Aalto <jari.aalto@cante.net>2009-09-12 16:46:53 +0000
commitbb70624e964126b7ac4ff085ba163a9c35ffa18f (patch)
treeba2dd4add13ada94b1899c6d4aca80195b80b74b /lib/sh
parentb72432fdcc59300c6fe7c9d6c8a31ad3447933f5 (diff)
downloadandroid_external_bash-bb70624e964126b7ac4ff085ba163a9c35ffa18f.tar.gz
android_external_bash-bb70624e964126b7ac4ff085ba163a9c35ffa18f.tar.bz2
android_external_bash-bb70624e964126b7ac4ff085ba163a9c35ffa18f.zip
Imported from ../bash-2.04.tar.gz.
Diffstat (limited to 'lib/sh')
-rw-r--r--lib/sh/Makefile.in109
-rw-r--r--lib/sh/clock.c78
-rw-r--r--lib/sh/getcwd.c16
-rw-r--r--lib/sh/getenv.c2
-rw-r--r--lib/sh/inet_aton.c205
-rw-r--r--lib/sh/itos.c2
-rw-r--r--lib/sh/makepath.c116
-rw-r--r--lib/sh/netopen.c228
-rw-r--r--lib/sh/rename.c18
-rw-r--r--lib/sh/setlinebuf.c38
-rw-r--r--lib/sh/shquote.c217
-rw-r--r--lib/sh/shtty.c284
-rw-r--r--lib/sh/strpbrk.c44
-rw-r--r--lib/sh/times.c77
-rw-r--r--lib/sh/timeval.c144
-rw-r--r--lib/sh/vprint.c4
-rw-r--r--lib/sh/zread.c127
-rw-r--r--lib/sh/zwrite.c61
18 files changed, 1725 insertions, 45 deletions
diff --git a/lib/sh/Makefile.in b/lib/sh/Makefile.in
index 439595c..789c544 100644
--- a/lib/sh/Makefile.in
+++ b/lib/sh/Makefile.in
@@ -1,13 +1,29 @@
#
# Makefile for the Bash library
#
+#
+# Copyright (C) 1998 Free Software Foundation, 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
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
srcdir = @srcdir@
VPATH = .:@srcdir@
topdir = @top_srcdir@
BUILD_DIR = @BUILD_DIR@
-POSIX_INC = ${topdir}/lib/posixheaders
+BASHINCDIR = ${topdir}/include
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
@@ -33,7 +49,7 @@ PROFILE_FLAGS = @PROFILE_FLAGS@
DEFS = @DEFS@
LOCAL_DEFS = @LOCAL_DEFS@
-INCLUDES = -I. -I../.. -I$(topdir) -I$(topdir)/lib -I$(POSIX_INC) -I$(srcdir)
+INCLUDES = -I. -I../.. -I$(topdir) -I$(topdir)/lib -I$(BASHINCDIR) -I$(srcdir)
CCFLAGS = ${PROFILE_FLAGS} ${INCLUDES} $(DEFS) $(LOCAL_DEFS) $(LOCAL_CFLAGS) \
$(CFLAGS) $(CPPFLAGS)
@@ -45,17 +61,19 @@ CCFLAGS = ${PROFILE_FLAGS} ${INCLUDES} $(DEFS) $(LOCAL_DEFS) $(LOCAL_CFLAGS) \
LIBRARY_NAME = libsh.a
# The C code source files for this library.
-CSOURCES = clktck.c getcwd.c getenv.c oslib.c setlinebuf.c \
+CSOURCES = clktck.c clock.c getcwd.c getenv.c oslib.c setlinebuf.c \
strcasecmp.c strerror.c strtod.c strtol.c strtoul.c \
- vprint.c itos.c rename.c
+ vprint.c itos.c rename.c zread.c zwrite.c shtty.c \
+ inet_aton.c netopen.c strpbrk.c timeval.c makepath.c
# The header files for this library.
HSOURCES =
# The object files contained in $(LIBRARY_NAME)
-OBJECTS = clktck.o getcwd.o getenv.o oslib.o setlinebuf.o \
+OBJECTS = clktck.o clock.o getcwd.o getenv.o oslib.o setlinebuf.o \
strcasecmp.o strerror.o strtod.o strtol.o strtoul.o \
- vprint.o itos.o rename.o
+ vprint.o itos.o rename.o zread.o zwrite.o shtty.o \
+ inet_aton.o netopen.o strpbrk.o timeval.o makepath.o
SUPPORT = Makefile
@@ -85,87 +103,124 @@ mostlyclean: clean
# rules for losing makes, like SunOS
clktck.o: clktck.c
+clock.o: clock.c
getcwd.o: getcwd.c
getenv.o: getenv.c
+inet_aton.o: inet_aton.c
itos.o: itos.c
+netopen.o: netopen.c
oslib.o: oslib.c
rename.o: rename.c
setlinebuf.o: setlinebuf.c
+shquote.o: shquote.c
+shtty.o: shtty.c
strcasecmp.o: strcasecmp.c
strerror.o: strerror.c
+strpbrk.o: strpbrk.c
strtod.o: strtod.c
strtol.o: strtol.c
strtoul.o: strtoul.c
+times.o: times.c
+timeval.o: timeval.c
vprint.o: vprint.c
+zread.o: zread.c
+zwrite.o: zwrite.c
# all files in the library depend on config.h
clktck.o: ${BUILD_DIR}/config.h
+clock.o: ${BUILD_DIR}/config.h
getcwd.o: ${BUILD_DIR}/config.h
getenv.o: ${BUILD_DIR}/config.h
+inet_aton.o: ${BUILD_DIR}/config.h
itos.o: ${BUILD_DIR}/config.h
+netopen.o: ${BUILD_DIR}/config.h
oslib.o: ${BUILD_DIR}/config.h
rename.o: ${BUILD_DIR}/config.h
setlinebuf.o: ${BUILD_DIR}/config.h
+shquote.o: ${BUILD_DIR}/config.h
+shtty.o: ${BUILD_DIR}/config.h
strcasecmp.o: ${BUILD_DIR}/config.h
strerror.o: ${BUILD_DIR}/config.h
+strpbrk.o: ${BUILD_DIR}/config.h
strtod.o: ${BUILD_DIR}/config.h
strtol.o: ${BUILD_DIR}/config.h
strtoul.o: ${BUILD_DIR}/config.h
+times.o: ${BUILD_DIR}/config.h
+timeval.o: ${BUILD_DIR}/config.h
vprint.o: ${BUILD_DIR}/config.h
+zread.o: ${BUILD_DIR}/config.h
+zwrite.o: ${BUILD_DIR}/config.h
clktck.o: ${topdir}/bashtypes.h
-getcwd.o: ${topdir}/bashtypes.h ${topdir}/bashansi.h ${topdir}/maxpath.h
-getcwd.o: ${POSIX_INC}/posixstat.h ${POSIX_INC}/posixdir.h
-getcwd.o: ${POSIX_INC}/memalloc.h ${POSIX_INC}/ansi_stdlib.h
+getcwd.o: ${topdir}/bashtypes.h ${topdir}/bashansi.h ${BASHINCDIR}/maxpath.h
+getcwd.o: ${BASHINCDIR}/posixstat.h ${BASHINCDIR}/posixdir.h
+getcwd.o: ${BASHINCDIR}/memalloc.h ${BASHINCDIR}/ansi_stdlib.h
-getenv.o: ${topdir}/bashansi.h ${topdir}/ansi_stdlib.h
-getenv.o: ${topdir}/shell.h ${topdir}/bashjmp.h ${topdir}/posixjmp.h
-getenv.o: ${topdir}/command.h ${topdir}/stdc.h ${topdir}/error.h
+getenv.o: ${topdir}/bashansi.h ${BASHINCDIR}/ansi_stdlib.h
+getenv.o: ${topdir}/shell.h ${topdir}/bashjmp.h ${BASHINCDIR}/posixjmp.h
+getenv.o: ${topdir}/command.h ${BASHINCDIR}/stdc.h ${topdir}/error.h
getenv.o: ${topdir}/general.h ${topdir}/bashtypes.h ${topdir}/variables.h
getenv.o: ${topdir}/array.h ${topdir}/hashlib.h ${topdir}/quit.h
getenv.o: ${topdir}/unwind_prot.h ${topdir}/dispose_cmd.h
getenv.o: ${topdir}/make_cmd.h ${topdir}/subst.h ${topdir}/sig.h
getenv.o: ${topdir}/pathnames.h ${topdir}/externs.h
-itos.o: ${topdir}/bashansi.h ${topdir}/ansi_stdlib.h
-itos.o: ${topdir}/shell.h ${topdir}/bashjmp.h ${topdir}/posixjmp.h
-itos.o: ${topdir}/command.h ${topdir}/stdc.h ${topdir}/error.h
+inet_aton.o: ${topdir}/bashansi.h ${BASHINCDIR}/ansi_stdlib.h
+inet_aton.o: ${BASHINCDIR}/stdc.h
+
+itos.o: ${topdir}/bashansi.h ${BASHINCDIR}/ansi_stdlib.h
+itos.o: ${topdir}/shell.h ${topdir}/bashjmp.h ${BASHINCDIR}/posixjmp.h
+itos.o: ${topdir}/command.h ${BASHINCDIR}/stdc.h ${topdir}/error.h
itos.o: ${topdir}/general.h ${topdir}/bashtypes.h ${topdir}/variables.h
itos.o: ${topdir}/array.h ${topdir}/hashlib.h ${topdir}/quit.h
itos.o: ${topdir}/unwind_prot.h ${topdir}/dispose_cmd.h
itos.o: ${topdir}/make_cmd.h ${topdir}/subst.h ${topdir}/sig.h
itos.o: ${topdir}/pathnames.h ${topdir}/externs.h
-oslib.o: ${topdir}/bashtypes.h ${topdir}/bashansi.h ${topdir}/maxpath.h
-oslib.o: ${topdir}/shell.h ${topdir}/bashjmp.h ${topdir}/posixjmp.h
-oslib.o: ${topdir}/command.h ${topdir}/stdc.h ${topdir}/error.h
+netopen.o: ${topdir}/bashansi.h ${BASHINCDIR}/ansi_stdlib.h
+
+oslib.o: ${topdir}/bashtypes.h ${topdir}/bashansi.h ${BASHINCDIR}/maxpath.h
+oslib.o: ${topdir}/shell.h ${topdir}/bashjmp.h ${BASHINCDIR}/posixjmp.h
+oslib.o: ${topdir}/command.h ${BASHINCDIR}/stdc.h ${topdir}/error.h
oslib.o: ${topdir}/general.h ${topdir}/bashtypes.h ${topdir}/variables.h
oslib.o: ${topdir}/array.h ${topdir}/hashlib.h ${topdir}/quit.h
oslib.o: ${topdir}/unwind_prot.h ${topdir}/dispose_cmd.h
oslib.o: ${topdir}/make_cmd.h ${topdir}/subst.h ${topdir}/sig.h
oslib.o: ${topdir}/pathnames.h ${topdir}/externs.h
-oslib.o: ${POSIX_INC}/posixstat.h ${POSIX_INC}/filecntl.h
-oslib.o: ${POSIX_INC}/ansi_stdlib.h
+oslib.o: ${BASHINCDIR}/posixstat.h ${BASHINCDIR}/filecntl.h
+oslib.o: ${BASHINCDIR}/ansi_stdlib.h
-rename.o: ${topdir}/bashtypes.h ${topdir}/stdc.h
+rename.o: ${topdir}/bashtypes.h ${BASHINCDIR}/stdc.h
-strcasecmp.o: ${topdir}/stdc.h ${topdir}/bashansi.h ${topdir}/ansi_stdlib.h
+shtty.o: ${BASHINCDIR}/shtty.h
+shtty.o: ${BASHINCDIR}/stdc.h
+
+strcasecmp.o: ${BASHINCDIR}/stdc.h ${topdir}/bashansi.h ${BASHINCDIR}/ansi_stdlib.h
strerror.o: ${topdir}/bashtypes.h
-strerror.o: ${topdir}/shell.h ${topdir}/bashjmp.h ${topdir}/posixjmp.h
-strerror.o: ${topdir}/command.h ${topdir}/stdc.h ${topdir}/error.h
+strerror.o: ${topdir}/shell.h ${topdir}/bashjmp.h ${BASHINCDIR}/posixjmp.h
+strerror.o: ${topdir}/command.h ${BASHINCDIR}/stdc.h ${topdir}/error.h
strerror.o: ${topdir}/general.h ${topdir}/bashtypes.h ${topdir}/variables.h
strerror.o: ${topdir}/array.h ${topdir}/hashlib.h ${topdir}/quit.h
strerror.o: ${topdir}/unwind_prot.h ${topdir}/dispose_cmd.h
strerror.o: ${topdir}/make_cmd.h ${topdir}/subst.h ${topdir}/sig.h
strerror.o: ${topdir}/pathnames.h ${topdir}/externs.h
+strpbrk.o: ${BASHINCDIR}/stdc.h
+
strtod.o: ${topdir}/bashansi.h
-strtod.o: ${POSIX_INC}/ansi_stdlib.h
+strtod.o: ${BASHINCDIR}/ansi_stdlib.h
strtol.o: ${topdir}/bashansi.h
-strtol.o: ${POSIX_INC}/ansi_stdlib.h
+strtol.o: ${BASHINCDIR}/ansi_stdlib.h
strtoul.o: ${topdir}/bashansi.h
-strtoul.o: ${POSIX_INC}/ansi_stdlib.h
+strtoul.o: ${BASHINCDIR}/ansi_stdlib.h
+
+times.o: ${BASHINCDIR}/systimes.h
+times.o: ${BASHINCDIR}/posixtime.h
+
+timeval.o: ${BASHINCDIR}/posixtime.h
+
+clock.o: ${BASHINCDIR}/posixtime.h
diff --git a/lib/sh/clock.c b/lib/sh/clock.c
new file mode 100644
index 0000000..9a91e38
--- /dev/null
+++ b/lib/sh/clock.c
@@ -0,0 +1,78 @@
+/* clock.c - operations on struct tms and clock_t's */
+
+/* Copyright (C) 1999 Free Software Foundation, Inc.
+
+ This file is part of GNU Bash, the Bourne Again SHell.
+
+ Bash is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 2, or (at your option) any later
+ version.
+
+ Bash is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with Bash; see the file COPYING. If not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA */
+
+#include <config.h>
+
+#if defined (HAVE_TIMES)
+
+#include <sys/types.h>
+#include <posixtime.h>
+
+#if defined (HAVE_SYS_TIMES_H)
+# include <sys/times.h>
+#endif
+
+#include <stdio.h>
+
+void
+clock_t_to_secs (t, sp, sfp)
+ clock_t t;
+ long *sp;
+ int *sfp;
+{
+ static long clk_tck = -1;
+
+ if (clk_tck == -1)
+ clk_tck = get_clk_tck ();
+
+ *sfp = t % clk_tck;
+ *sfp = (*sfp * 1000) / clk_tck;
+
+ *sp = t / clk_tck;
+
+ /* Sanity check */
+ if (*sfp >= 1000)
+ {
+ *sp += 1;
+ *sfp -= 1000;
+ }
+}
+
+/* Print the time defined by a clock_t (returned by the `times' and `time'
+ system calls) in a standard way to stdio stream FP. This is scaled in
+ terms of the value of CLK_TCK, which is what is returned by the
+ `times' call. */
+void
+print_clock_t (fp, t)
+ FILE *fp;
+ clock_t t;
+{
+ int minutes, seconds_fraction;
+ long seconds;
+
+ clock_t_to_secs (t, &seconds, &seconds_fraction);
+
+ minutes = seconds / 60;
+ seconds %= 60;
+
+ fprintf (fp, "%0dm%0ld.%03ds", minutes, seconds, seconds_fraction);
+}
+#endif /* HAVE_TIMES */
+
diff --git a/lib/sh/getcwd.c b/lib/sh/getcwd.c
index 9a8b31f..d39655d 100644
--- a/lib/sh/getcwd.c
+++ b/lib/sh/getcwd.c
@@ -15,8 +15,8 @@
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
- not, write to the Free Software Foundation, Inc., 675 Mass Ave,
- Cambridge, MA 02139, USA. */
+ not, write to the Free Software Foundation, Inc.,
+ 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
#include <config.h>
@@ -64,6 +64,10 @@ extern int errno;
# define lstat stat
#endif
+#if !defined (NULL)
+# define NULL 0
+#endif
+
/* Get the pathname of the current working directory,
and put it in SIZE bytes of BUF. Returns NULL if the
directory couldn't be determined or SIZE was too small.
@@ -138,14 +142,14 @@ getcwd (buf, size)
char *new;
if (dotlist == dots)
{
- new = malloc (dotsize * 2 + 1);
+ new = (char *)malloc (dotsize * 2 + 1);
if (new == NULL)
goto lose;
memcpy (new, dots, dotsize);
}
else
{
- new = realloc ((PTR) dotlist, dotsize * 2 + 1);
+ new = (char *)realloc ((PTR) dotlist, dotsize * 2 + 1);
if (new == NULL)
goto lose;
}
@@ -222,13 +226,13 @@ getcwd (buf, size)
if (pathbuf == path)
{
- new = malloc (pathsize * 2);
+ new = (char *)malloc (pathsize * 2);
if (!new)
goto lose;
}
else
{
- new = realloc ((PTR) pathbuf, (pathsize * 2));
+ new = (char *)realloc ((PTR) pathbuf, (pathsize * 2));
if (!new)
goto lose;
pathp = new + space;
diff --git a/lib/sh/getenv.c b/lib/sh/getenv.c
index 6353615..3d81ee4 100644
--- a/lib/sh/getenv.c
+++ b/lib/sh/getenv.c
@@ -56,7 +56,7 @@ getenv (name)
{
FREE (last_tempenv_value);
- last_tempenv_value = savestring (value_cell (var));
+ last_tempenv_value = value_cell (var) ? savestring (value_cell (var)) : (char *)NULL;
dispose_variable (var);
return (last_tempenv_value);
}
diff --git a/lib/sh/inet_aton.c b/lib/sh/inet_aton.c
new file mode 100644
index 0000000..28cd979
--- /dev/null
+++ b/lib/sh/inet_aton.c
@@ -0,0 +1,205 @@
+/* Snagged from GNU C library, version 2.0.3. */
+
+/*
+ * ++Copyright++ 1983, 1990, 1993
+ * -
+ * Copyright (c) 1983, 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. 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.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * 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, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION 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.
+ * -
+ * --Copyright--
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)inet_addr.c 8.1 (Berkeley) 6/17/93";
+static char rcsid[] = "$Id: inet_addr.c,v 1.5 1996/08/14 03:48:37 drepper Exp $";
+#endif /* LIBC_SCCS and not lint */
+
+#include <config.h>
+
+#if !defined (HAVE_INET_ATON) && defined (HAVE_NETWORK) && defined (HAVE_NETINET_IN_H) && defined (HAVE_ARPA_INET_H)
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
+#include <bashansi.h>
+#include <ctype.h>
+#include <stdc.h>
+
+#ifndef INADDR_NONE
+# define INADDR_NONE 0xffffffff
+#endif
+
+/* these are compatibility routines, not needed on recent BSD releases */
+
+#if 0
+/* Not used, not needed. */
+/*
+ * Ascii internet address interpretation routine.
+ * The value returned is in network order.
+ */
+u_long
+inet_addr(cp)
+ register const char *cp;
+{
+ struct in_addr val;
+
+ if (inet_aton(cp, &val))
+ return (val.s_addr);
+ return (INADDR_NONE);
+}
+#endif
+
+/*
+ * Check whether "cp" is a valid ascii representation
+ * of an Internet address and convert to a binary address.
+ * Returns 1 if the address is valid, 0 if not.
+ * This replaces inet_addr, the return value from which
+ * cannot distinguish between failure and a local broadcast address.
+ */
+int
+inet_aton(cp, addr)
+ register const char *cp;
+ struct in_addr *addr;
+{
+ register u_bits32_t val;
+ register int base, n;
+ register char c;
+ u_int parts[4];
+ register u_int *pp = parts;
+
+ c = *cp;
+ for (;;) {
+ /*
+ * Collect number up to ``.''.
+ * Values are specified as for C:
+ * 0x=hex, 0=octal, isdigit=decimal.
+ */
+ if (!isdigit(c))
+ return (0);
+ val = 0; base = 10;
+ if (c == '0') {
+ c = *++cp;
+ if (c == 'x' || c == 'X')
+ base = 16, c = *++cp;
+ else
+ base = 8;
+ }
+ for (;;) {
+ if (isascii(c) && isdigit(c)) {
+ val = (val * base) + (c - '0');
+ c = *++cp;
+ } else if (base == 16 && isascii(c) && isxdigit(c)) {
+ val = (val << 4) |
+ (c + 10 - (islower(c) ? 'a' : 'A'));
+ c = *++cp;
+ } else
+ break;
+ }
+ if (c == '.') {
+ /*
+ * Internet format:
+ * a.b.c.d
+ * a.b.c (with c treated as 16 bits)
+ * a.b (with b treated as 24 bits)
+ */
+ if (pp >= parts + 3)
+ return (0);
+ *pp++ = val;
+ c = *++cp;
+ } else
+ break;
+ }
+ /*
+ * Check for trailing characters.
+ */
+ if (c != '\0' && (!isascii(c) || !isspace(c)))
+ return (0);
+ /*
+ * Concoct the address according to
+ * the number of parts specified.
+ */
+ n = pp - parts + 1;
+ switch (n) {
+
+ case 0:
+ return (0); /* initial nondigit */
+
+ case 1: /* a -- 32 bits */
+ break;
+
+ case 2: /* a.b -- 8.24 bits */
+ if (val > 0xffffff)
+ return (0);
+ val |= parts[0] << 24;
+ break;
+
+ case 3: /* a.b.c -- 8.8.16 bits */
+ if (val > 0xffff)
+ return (0);
+ val |= (parts[0] << 24) | (parts[1] << 16);
+ break;
+
+ case 4: /* a.b.c.d -- 8.8.8.8 bits */
+ if (val > 0xff)
+ return (0);
+ val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
+ break;
+ }
+ if (addr)
+ addr->s_addr = htonl(val);
+ return (1);
+}
+
+#endif /* !HAVE_INET_ATON */
diff --git a/lib/sh/itos.c b/lib/sh/itos.c
index 5105cb7..dee7883 100644
--- a/lib/sh/itos.c
+++ b/lib/sh/itos.c
@@ -16,7 +16,7 @@
You should have received a copy of the GNU General Public License along
with Bash; see the file COPYING. If not, write to the Free Software
- Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
+ Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
#include <config.h>
diff --git a/lib/sh/makepath.c b/lib/sh/makepath.c
new file mode 100644
index 0000000..dfc1210
--- /dev/null
+++ b/lib/sh/makepath.c
@@ -0,0 +1,116 @@
+/* makepath.c - glue PATH and DIR together into a full pathname. */
+
+/* Copyright (C) 1987, 1989, 1991 Free Software Foundation, Inc.
+
+ This file is part of GNU Bash, the Bourne Again SHell.
+
+ Bash is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 2, or (at your option) any later
+ version.
+
+ Bash is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with Bash; see the file COPYING. If not, write to the Free Software
+ Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
+
+#include <config.h>
+
+#if defined (HAVE_UNISTD_H)
+# ifdef _MINIX
+# include <sys/types.h>
+# endif
+# include <unistd.h>
+#endif
+
+#include "bashansi.h"
+#include "shell.h"
+
+#include <tilde/tilde.h>
+
+#ifndef NULL
+# define NULL 0
+#endif
+
+/* MAKE SURE THESE AGREE WITH ../../externs.h. */
+
+#ifndef MP_DOTILDE
+# define MP_DOTILDE 0x01
+# define MP_DOCWD 0x02
+# define MP_RMDOT 0x04
+#endif
+
+extern char *get_working_directory __P((char *));
+
+/* Take PATH, an element from, e.g., $CDPATH, and DIR, a directory name,
+ and paste them together into PATH/DIR. Tilde expansion is performed on
+ PATH if (flags & MP_DOTILDE) is non-zero. If PATH is NULL or the empty
+ string, it is converted to the current directory. A full pathname is
+ used if (flags & MP_DOCWD) is non-zero, otherwise `./' is used. If
+ (flags & MP_RMDOT) is non-zero, any `./' is removed from the beginning
+ of DIR. */
+
+#define MAKEDOT() \
+ do { \
+ xpath = xmalloc (2); \
+ xpath[0] = '.'; \
+ xpath[1] = '\0'; \
+ pathlen = 1; \
+ } while (0)
+
+char *
+sh_makepath (path, dir, flags)
+ char *path, *dir;
+ int flags;
+{
+ int dirlen, pathlen;
+ char *ret, *xpath;
+
+ if (path == 0 || *path == '\0')
+ {
+ if (flags & MP_DOCWD)
+ {
+ xpath = get_working_directory ("sh_makepath");
+ if (xpath == 0)
+ {
+ ret = get_string_value ("PWD");
+ if (ret)
+ xpath = savestring (ret);
+ }
+ if (xpath == 0)
+ MAKEDOT();
+ else
+ pathlen = strlen (xpath);
+ }
+ else
+ MAKEDOT();
+ }
+ else
+ {
+ xpath = ((flags & MP_DOTILDE) && *path == '~') ? bash_tilde_expand (path) : path;
+ pathlen = strlen (xpath);
+ }
+
+ dirlen = strlen (dir);
+ if ((flags & MP_RMDOT) && dir[0] == '.' && dir[1] == '/')
+ {
+ dir += 2;
+ dirlen -= 2;
+ }
+
+ ret = xmalloc (2 + dirlen + pathlen);
+ strcpy (ret, xpath);
+ if (xpath[pathlen - 1] != '/')
+ {
+ ret[pathlen++] = '/';
+ ret[pathlen] = '\0';
+ }
+ strcpy (ret + pathlen, dir);
+ if (xpath != path)
+ free (xpath);
+ return (ret);
+}
diff --git a/lib/sh/netopen.c b/lib/sh/netopen.c
new file mode 100644
index 0000000..789a9b3
--- /dev/null
+++ b/lib/sh/netopen.c
@@ -0,0 +1,228 @@
+/*
+ * netopen.c -- functions to make tcp/udp connections
+ *
+ * Chet Ramey
+ * chet@ins.CWRU.Edu
+ */
+
+/* Copyright (C) 1987,1991 Free Software Foundation, Inc.
+
+ This file is part of GNU Bash, the Bourne Again SHell.
+
+ Bash is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ Bash is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Bash; see the file COPYING. If not, write to the Free
+ Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
+
+#include <config.h>
+
+#if defined (HAVE_NETWORK)
+
+#include <stdio.h>
+#include <sys/types.h>
+
+#if defined (HAVE_SYS_SOCKET_H)
+# include <sys/socket.h>
+#endif
+
+#if defined (HAVE_NETINET_IN_H)
+# include <netinet/in.h>
+#endif
+
+#if defined (HAVE_NETDB_H)
+# include <netdb.h>
+#endif
+
+#if defined (HAVE_ARPA_INET_H)
+# include <arpa/inet.h>
+#endif
+
+#include <bashansi.h>
+#include <ctype.h>
+#include <errno.h>
+
+#ifndef errno
+extern int errno;
+#endif
+
+#if !defined (HAVE_INET_ATON)
+extern int inet_aton ();
+#endif
+
+extern char *xmalloc ();
+
+/* Stuff the internet address corresponding to HOST into AP, in network
+ byte order. Return 1 on success, 0 on failure. */
+
+static int
+_getaddr (host, ap)
+ char *host;
+ struct in_addr *ap;
+{
+ struct hostent *h;
+ int r;
+
+ r = 0;
+ if (isdigit (host[0]))
+ {
+ /* If the first character is a digit, guess that it's an
+ Internet address and return immediately if inet_aton succeeds. */
+ r = inet_aton (host, ap);
+ if (r)
+ return r;
+ }
+#if !defined (HAVE_GETHOSTBYNAME)
+ return 0;
+#else
+ h = gethostbyname (host);
+ if (h && h->h_addr)
+ {
+ bcopy(h->h_addr, (char *)ap, h->h_length);
+ return 1;
+ }
+#endif
+ return 0;
+
+}
+
+/* Return 1 if SERV is a valid port number and stuff the converted value into
+ PP in network byte order. */
+static int
+_getserv (serv, pp)
+ char *serv;
+ unsigned short *pp;
+{
+ long l;
+ unsigned short s;
+
+ if (legal_number (serv, &l))
+ {
+ if (l > 65535)
+ return 0;
+ s = (unsigned short)(l & 0xFFFF);
+ s = htons (s);
+ if (pp)
+ *pp = s;
+ return 1;
+ }
+ else
+ return 0;
+}
+
+static int
+_netopen(host, serv, typ)
+ char *host, *serv;
+ int typ;
+{
+ struct in_addr ina;
+ struct sockaddr_in sin;
+ unsigned short p;
+ int s;
+ char **cp;
+
+ if (_getaddr(host, &ina) == 0)
+ {
+ internal_error ("%s: host unknown", host);
+ return -1;
+ }
+
+ if (_getserv(serv, &p) == 0)
+ {
+ internal_error("%s: invalid service", serv);
+ return -1;
+ }
+
+ bzero ((char *)&sin, sizeof(sin));
+ sin.sin_family = AF_INET;
+ sin.sin_port = p;
+ sin.sin_addr = ina;
+
+ s = socket(AF_INET, (typ == 't') ? SOCK_STREAM : SOCK_DGRAM, 0);
+ if (s < 0)
+ {
+ sys_error ("socket");
+ return (-1);
+ }
+
+ if (connect (s, (struct sockaddr *)&sin, sizeof (sin)) < 0)
+ {
+ sys_error("connect");
+ close(s);
+ return (-1);
+ }
+
+ return(s);
+}
+
+/*
+ * Open a TCP or UDP connection given a path like `/dev/tcp/host/port' to
+ * host `host' on port `port' and return the connected socket.
+ */
+int
+netopen (path)
+ char *path;
+{
+ char *np, *s, *t;
+ int fd;
+
+ np = xmalloc (strlen (path) + 1);
+ strcpy (np, path);
+
+ s = np + 9;
+ t = strchr (s, '/');
+ if (t == 0)
+ {
+ internal_error ("%s: bad network path specification", path);
+ return -1;
+ }
+ *t++ = '\0';
+ fd = _netopen (s, t, path[5]);
+ free (np);
+
+ return fd;
+}
+
+#if 0
+/*
+ * Open a TCP connection to host `host' on the port defined for service
+ * `serv' and return the connected socket.
+ */
+int
+tcpopen (host, serv)
+ char *host, *serv;
+{
+ return (_netopen (host, serv, 't'));
+}
+
+/*
+ * Open a UDP connection to host `host' on the port defined for service
+ * `serv' and return the connected socket.
+ */
+int
+udpopen (host, serv)
+ char *host, *serv;
+{
+ return _netopen (host, serv, 'u');
+}
+#endif
+
+#else /* !HAVE_NETWORK */
+
+int
+netopen (path)
+ char *path;
+{
+ internal_error ("network operations not supported");
+ return -1;
+}
+
+#endif /* !HAVE_NETWORK */
diff --git a/lib/sh/rename.c b/lib/sh/rename.c
index 799cb69..cc12856 100644
--- a/lib/sh/rename.c
+++ b/lib/sh/rename.c
@@ -2,6 +2,24 @@
* rename - rename a file
*/
+/* Copyright (C) 1999 Free Software Foundation, Inc.
+
+ This file is part of GNU Bash, the Bourne Again SHell.
+
+ Bash is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ Bash is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Bash; see the file COPYING. If not, write to the Free
+ Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
+
#include <config.h>
#if !defined (HAVE_RENAME)
diff --git a/lib/sh/setlinebuf.c b/lib/sh/setlinebuf.c
index 05f9579..fb097de 100644
--- a/lib/sh/setlinebuf.c
+++ b/lib/sh/setlinebuf.c
@@ -20,22 +20,44 @@
#include <config.h>
-#if !defined (HAVE_SETLINEBUF)
-
#include <stdio.h>
+extern char *xmalloc();
+
+#if defined (USING_BASH_MALLOC)
+# define LBUF_BUFSIZE 1008
+#else
+# define LBUF_BUFSIZE BUFSIZ
+#endif
+
/* Cause STREAM to buffer lines as opposed to characters or blocks. */
int
-setlinebuf (stream)
+sh_setlinebuf (stream)
FILE *stream;
{
-#if defined (_IOLBF)
+ char *local_linebuf;
+
+#if !defined (HAVE_SETLINEBUF) && !defined (HAVE_SETVBUF)
+ return (0);
+#endif
+
+#if defined (USING_BASH_MALLOC)
+ local_linebuf = xmalloc (LBUF_BUFSIZE);
+#else
+ local_linebuf = (char *)NULL;
+#endif
+
+#if defined (HAVE_SETVBUF)
+
# if defined (SETVBUF_REVERSED)
- setvbuf (stream, _IOLBF, (char *)NULL, BUFSIZ);
+ return (setvbuf (stream, _IOLBF, local_linebuf, LBUF_BUFSIZE));
# else /* !SETVBUF_REVERSED */
- setvbuf (stream, (char *)NULL, _IOLBF, BUFSIZ);
+ return (setvbuf (stream, local_linebuf, _IOLBF, LBUF_BUFSIZE));
# endif /* !SETVBUF_REVERSED */
-#endif /* _IOLBF */
+# else /* !HAVE_SETVBUF */
+
+ setlinebuf (stream));
return (0);
+
+#endif /* !HAVE_SETVBUF */
}
-#endif /* !HAVE_SETLINEBUF */
diff --git a/lib/sh/shquote.c b/lib/sh/shquote.c
new file mode 100644
index 0000000..ab8009d
--- /dev/null
+++ b/lib/sh/shquote.c
@@ -0,0 +1,217 @@
+/* Copyright (C) 1999 Free Software Foundation, Inc.
+
+ This file is part of GNU Bash, the Bourne Again SHell.
+
+ Bash is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 2, or (at your option) any later
+ version.
+
+ Bash is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with Bash; see the file COPYING. If not, write to the Free Software
+ Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
+
+#include <config.h>
+
+#if defined (HAVE_UNISTD_H)
+# ifdef _MINIX
+# include <sys/types.h>
+# endif
+# include <unistd.h>
+#endif
+
+#include <stdio.h>
+
+#if !defined(slashify_in_quotes)
+# define slashify_in_quotes "\\`$\"\n"
+#endif
+
+extern char *xmalloc ();
+
+/* **************************************************************** */
+/* */
+/* Functions for quoting strings to be re-read as input */
+/* */
+/* **************************************************************** */
+
+/* Return a new string which is the single-quoted version of STRING.
+ Used by alias and trap, among others. */
+char *
+single_quote (string)
+ char *string;
+{
+ register int c;
+ char *result, *r, *s;
+
+ result = xmalloc (3 + (4 * strlen (string)));
+ r = result;
+ *r++ = '\'';
+
+ for (s = string; s && (c = *s); s++)
+ {
+ *r++ = c;
+
+ if (c == '\'')
+ {
+ *r++ = '\\'; /* insert escaped single quote */
+ *r++ = '\'';
+ *r++ = '\''; /* start new quoted string */
+ }
+ }
+
+ *r++ = '\'';
+ *r = '\0';
+
+ return (result);
+}
+
+/* Quote STRING using double quotes. Return a new string. */
+char *
+double_quote (string)
+ char *string;
+{
+ register int c;
+ char *result, *r, *s;
+
+ result = xmalloc (3 + (2 * strlen (string)));
+ r = result;
+ *r++ = '"';
+
+ for (s = string; s && (c = *s); s++)
+ {
+ switch (c)
+ {
+ case '"':
+ case '$':
+ case '`':
+ case '\\':
+ case '\n': /* XXX */
+ *r++ = '\\';
+ default:
+ *r++ = c;
+ break;
+ }
+ }
+
+ *r++ = '"';
+ *r = '\0';
+
+ return (result);
+}
+
+/* Remove backslashes that are quoting characters that are special between
+ double quotes. Return a new string. */
+char *
+un_double_quote (string)
+ char *string;
+{
+ register int c, pass_next;
+ char *result, *r, *s;
+
+ r = result = xmalloc (strlen (string) + 1);
+
+ for (pass_next = 0, s = string; s && (c = *s); s++)
+ {
+ if (pass_next)
+ {
+ *r++ = c;
+ pass_next = 0;
+ continue;
+ }
+ if (c == '\\' && strchr (slashify_in_quotes, s[1]))
+ {
+ pass_next = 1;
+ continue;
+ }
+ *r++ = c;
+ }
+
+ *r = '\0';
+ return result;
+}
+
+/* Quote special characters in STRING using backslashes. Return a new
+ string. */
+char *
+backslash_quote (string)
+ char *string;
+{
+ int c;
+ char *result, *r, *s;
+
+ result = xmalloc (2 * strlen (string) + 1);
+
+ for (r = result, s = string; s && (c = *s); s++)
+ {
+ switch (c)
+ {
+ case ' ': case '\t': case '\n': /* IFS white space */
+ case '\'': case '"': case '\\': /* quoting chars */
+ case '|': case '&': case ';': /* shell metacharacters */
+ case '(': case ')': case '<': case '>':
+ case '!': case '{': case '}': /* reserved words */
+ case '*': case '[': case '?': case ']': /* globbing chars */
+ case '^':
+ case '$': case '`': /* expansion chars */
+ *r++ = '\\';
+ *r++ = c;
+ break;
+#if 0
+ case '~': /* tilde expansion */
+ if (s == string || s[-1] == '=' || s[-1] == ':')
+ *r++ = '\\';
+ *r++ = c;
+ break;
+#endif
+ case '#': /* comment char */
+ if (s == string)
+ *r++ = '\\';
+ /* FALLTHROUGH */
+ default:
+ *r++ = c;
+ break;
+ }
+ }
+
+ *r = '\0';
+ return (result);
+}
+
+int
+contains_shell_metas (string)
+ char *string;
+{
+ char *s;
+
+ for (s = string; s && *s; s++)
+ {
+ switch (*s)
+ {
+ case ' ': case '\t': case '\n': /* IFS white space */
+ case '\'': case '"': case '\\': /* quoting chars */
+ case '|': case '&': case ';': /* shell metacharacters */
+ case '(': case ')': case '<': case '>':
+ case '!': case '{': case '}': /* reserved words */
+ case '*': case '[': case '?': case ']': /* globbing chars */
+ case '^':
+ case '$': case '`': /* expansion chars */
+ return (1);
+ case '~': /* tilde expansion */
+ if (s == string || s[-1] == '=' || s[-1] == ':')
+ return (1);
+ case '#':
+ if (s == string) /* comment char */
+ return (1);
+ /* FALLTHROUGH */
+ default:
+ break;
+ }
+ }
+
+ return (0);
+}
diff --git a/lib/sh/shtty.c b/lib/sh/shtty.c
new file mode 100644
index 0000000..15cc82f
--- /dev/null
+++ b/lib/sh/shtty.c
@@ -0,0 +1,284 @@
+/* Copyright (C) 1999 Free Software Foundation, Inc.
+
+ This file is part of GNU Bash, the Bourne Again SHell.
+
+ Bash is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 2, or (at your option) any later
+ version.
+
+ Bash is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with Bash; see the file COPYING. If not, write to the Free Software
+ Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
+
+/*
+ * shtty.c -- abstract interface to the terminal, focusing on capabilities.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
+#include <shtty.h>
+
+static TTYSTRUCT ttin, ttout;
+static int ttsaved = 0;
+
+int
+ttgetattr(fd, ttp)
+int fd;
+TTYSTRUCT *ttp;
+{
+#ifdef TERMIOS_TTY_DRIVER
+ return tcgetattr(fd, ttp);
+#else
+# ifdef TERMIO_TTY_DRIVER
+ return ioctl(fd, TCGETA, ttp);
+# else
+ return ioctl(fd, TIOCGETP, ttp);
+# endif
+#endif
+}
+
+int
+ttsetattr(fd, ttp)
+int fd;
+TTYSTRUCT *ttp;
+{
+#ifdef TERMIOS_TTY_DRIVER
+ return tcsetattr(fd, TCSADRAIN, ttp);
+#else
+# ifdef TERMIO_TTY_DRIVER
+ return ioctl(fd, TCSETAW, ttp);
+# else
+ return ioctl(fd, TIOCSETN, ttp);
+# endif
+#endif
+}
+
+void
+ttsave()
+{
+ if (ttsaved)
+ return;
+ ttgetattr (0, &ttin);
+ ttgetattr (1, &ttout);
+ ttsaved = 1;
+}
+
+void
+ttrestore()
+{
+ if (ttsaved == 0)
+ return;
+ ttsetattr (0, &ttin);
+ ttsetattr (1, &ttout);
+ ttsaved = 0;
+}
+
+/* Retrieve the attributes associated with tty fd FD. */
+TTYSTRUCT *
+ttattr (fd)
+ int fd;
+{
+ if (ttsaved == 0)
+ return ((TTYSTRUCT *)0);
+ if (fd == 0)
+ return &ttin;
+ else if (fd == 1)
+ return &ttout;
+ else
+ return ((TTYSTRUCT *)0);
+}
+
+/*
+ * Change attributes in ttp so that when it is installed using
+ * ttsetattr, the terminal will be in one-char-at-a-time mode.
+ */
+int
+tt_setonechar(ttp)
+ TTYSTRUCT *ttp;
+{
+#if defined (TERMIOS_TTY_DRIVER) || defined (TERMIO_TTY_DRIVER)
+
+ /* XXX - might not want this -- it disables erase and kill processing. */
+ ttp->c_lflag &= ~ICANON;
+
+ ttp->c_lflag |= ISIG;
+# ifdef IEXTEN
+ ttp->c_lflag |= IEXTEN;
+# endif
+
+ ttp->c_iflag |= ICRNL; /* make sure we get CR->NL on input */
+ ttp->c_iflag &= ~INLCR; /* but no NL->CR */
+
+# ifdef OPOST
+ ttp->c_oflag |= OPOST;
+# endif
+# ifdef ONLCR
+ ttp->c_oflag |= ONLCR;
+# endif
+# ifdef OCRNL
+ ttp->c_oflag &= ~OCRNL;
+# endif
+# ifdef ONOCR
+ ttp->c_oflag &= ~ONOCR;
+# endif
+# ifdef ONLRET
+ ttp->c_oflag &= ~ONLRET;
+# endif
+
+ ttp->c_cc[VMIN] = 1;
+ ttp->c_cc[VTIME] = 0;
+
+#else
+
+ ttp->sg_flags |= CBREAK;
+
+#endif
+
+ return 0;
+}
+
+/* Set the terminal into one-character-at-a-time mode */
+int
+ttonechar ()
+{
+ TTYSTRUCT tt;
+
+ if (ttsaved == 0)
+ return -1;
+ tt = ttin;
+ if (tt_setonechar(&tt) < 0)
+ return -1;
+ return (ttsetattr (0, &tt));
+}
+
+/*
+ * Change attributes in ttp so that when it is installed using
+ * ttsetattr, the terminal will be in no-echo mode.
+ */
+int
+tt_setnoecho(ttp)
+ TTYSTRUCT *ttp;
+{
+#if defined (TERMIOS_TTY_DRIVER) || defined (TERMIO_TTY_DRIVER)
+ ttp->c_lflag &= ~(ECHO|ECHOK|ECHONL);
+#else
+ ttp->sg_flags &= ~ECHO;
+#endif
+
+ return 0;
+}
+
+/* Set the terminal into no-echo mode */
+int
+ttnoecho ()
+{
+ TTYSTRUCT tt;
+
+ if (ttsaved == 0)
+ return -1;
+ tt = ttin;
+ if (tt_setnoecho (&tt) < 0)
+ return -1;
+ return (ttsetattr (0, &tt));
+}
+
+/*
+ * Change attributes in ttp so that when it is installed using
+ * ttsetattr, the terminal will be in eight-bit mode (pass8).
+ */
+int
+tt_seteightbit (ttp)
+ TTYSTRUCT *ttp;
+{
+#if defined (TERMIOS_TTY_DRIVER) || defined (TERMIO_TTY_DRIVER)
+ ttp->c_iflag &= ~ISTRIP;
+ ttp->c_cflag |= CS8;
+ ttp->c_cflag &= ~PARENB;
+#else
+ ttp->sg_flags |= ANYP;
+#endif
+
+ return 0;
+}
+
+/* Set the terminal into eight-bit mode */
+int
+tteightbit ()
+{
+ TTYSTRUCT tt;
+
+ if (ttsaved == 0)
+ return -1;
+ tt = ttin;
+ if (tt_seteightbit (&tt) < 0)
+ return -1;
+ return (ttsetattr (0, &tt));
+}
+
+/*
+ * Change attributes in ttp so that when it is installed using
+ * ttsetattr, the terminal will be in non-canonical input mode.
+ */
+int
+tt_setnocanon (ttp)
+ TTYSTRUCT *ttp;
+{
+#if defined (TERMIOS_TTY_DRIVER) || defined (TERMIO_TTY_DRIVER)
+ ttp->c_lflag &= ~ICANON;
+#endif
+
+ return 0;
+}
+
+/* Set the terminal into non-canonical mode */
+int
+ttnocanon ()
+{
+ TTYSTRUCT tt;
+
+ if (ttsaved == 0)
+ return -1;
+ tt = ttin;
+ if (tt_setnocanon (&tt) < 0)
+ return -1;
+ return (ttsetattr (0, &tt));
+}
+
+/*
+ * Change attributes in ttp so that when it is installed using
+ * ttsetattr, the terminal will be in cbreak, no-echo mode.
+ */
+int
+tt_setcbreak(ttp)
+ TTYSTRUCT *ttp;
+{
+ if (tt_setonechar (ttp) < 0)
+ return -1;
+ return (tt_setnoecho (ttp));
+}
+
+/* Set the terminal into cbreak (no-echo, one-character-at-a-time) mode */
+int
+ttcbreak ()
+{
+ TTYSTRUCT tt;
+
+ if (ttsaved == 0)
+ return -1;
+ tt = ttin;
+ if (tt_setcbreak (&tt) < 0)
+ return -1;
+ return (ttsetattr (0, &tt));
+}
diff --git a/lib/sh/strpbrk.c b/lib/sh/strpbrk.c
new file mode 100644
index 0000000..3c493a8
--- /dev/null
+++ b/lib/sh/strpbrk.c
@@ -0,0 +1,44 @@
+/* Copyright (C) 1991, 1994 Free Software Foundation, Inc.
+ NOTE: The canonical source of this file is maintained with the GNU C Library.
+ Bugs can be reported to bug-glibc@prep.ai.mit.edu.
+
+ 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 the
+ Free Software Foundation; either version 2, or (at your option) any
+ later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#if !defined (HAVE_STRPBRK)
+
+#include <stdc.h>
+
+/* Find the first ocurrence in S of any character in ACCEPT. */
+char *
+strpbrk (s, accept)
+ register const char *s;
+ register const char *accept;
+{
+ while (*s != '\0')
+ {
+ const char *a = accept;
+ while (*a != '\0')
+ if (*a++ == *s)
+ return (char *) s;
+ ++s;
+ }
+
+ return 0;
+}
+#endif
diff --git a/lib/sh/times.c b/lib/sh/times.c
new file mode 100644
index 0000000..240aafe
--- /dev/null
+++ b/lib/sh/times.c
@@ -0,0 +1,77 @@
+/* times.c - times(3) library function */
+
+/* Copyright (C) 1999 Free Software Foundation, Inc.
+
+ This file is part of GNU Bash, the Bourne Again SHell.
+
+ Bash is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 2, or (at your option) any later
+ version.
+
+ Bash is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with Bash; see the file COPYING. If not, write to the Free Software
+ Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
+
+#include <config.h>
+
+#if !defined (HAVE_TIMES)
+
+#include <sys/types.h>
+#include <posixtime.h>
+#include <systimes.h>
+
+#if defined (HAVE_SYS_RESOURCE_H) && defined (HAVE_GETRUSAGE)
+# include <sys/resource.h>
+#endif /* HAVE_SYS_RESOURCE_H && HAVE_GETRUSAGE */
+
+extern long get_clk_tck();
+
+#define CONVTCK(r) (r.tv_sec * clk_tck + r.tv_usec / (1000000 / clk_tck))
+
+clock_t
+times(tms)
+ struct tms *tms;
+{
+ clock_t rv;
+ static long clk_tck = -1;
+
+#if defined (HAVE_GETRUSAGE)
+ struct timeval tv;
+ struct rusage ru;
+
+ if (clk_tck == -1)
+ clk_tck = get_clk_tck();
+
+ if (getrusage(RUSAGE_SELF, &ru) < 0)
+ return ((clock_t)-1);
+ tms->tms_utime = CONVTCK(ru.ru_utime);
+ tms->tms_stime = CONVTCK(ru.ru_stime);
+
+ if (getrusage(RUSAGE_CHILDREN, &ru) < 0)
+ return ((clock_t)-1);
+ tms->tms_cutime = CONVTCK(ru.ru_utime);
+ tms->tms_cstime = CONVTCK(ru.ru_stime);
+
+ if (gettimeofday(&tv, (struct timezone *) 0) < 0)
+ return ((clock_t)-1);
+ rv = (clock_t)(CONVTCK(tv));
+#else /* !HAVE_GETRUSAGE */
+ if (clk_tck == -1)
+ clk_tck = get_clk_tck();
+
+ /* We can't do anything. */
+ tms->tms_utime = tms->tms_stime = (clock_t)0;
+ tms->tms_cutime = tms->tms_cstime = (clock_t)0;
+
+ rv = (clock_t)time((time_t *)0) * clk_tck;
+# endif /* HAVE_GETRUSAGE */
+
+ return rv;
+}
+#endif /* !HAVE_TIMES */
diff --git a/lib/sh/timeval.c b/lib/sh/timeval.c
new file mode 100644
index 0000000..809d411
--- /dev/null
+++ b/lib/sh/timeval.c
@@ -0,0 +1,144 @@
+/* timeval.c - functions to perform operations on struct timevals */
+
+/* Copyright (C) 1999 Free Software Foundation, Inc.
+
+ This file is part of GNU Bash, the Bourne Again SHell.
+
+ Bash is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 2, or (at your option) any later
+ version.
+
+ Bash is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with Bash; see the file COPYING. If not, write to the Free Software
+ Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
+
+#include <config.h>
+
+#if defined (HAVE_TIMEVAL)
+
+#include <sys/types.h>
+#include <posixtime.h>
+
+#include <stdio.h>
+
+struct timeval *
+difftimeval (d, t1, t2)
+ struct timeval *d, *t1, *t2;
+{
+ d->tv_sec = t2->tv_sec - t1->tv_sec;
+ d->tv_usec = t2->tv_usec - t1->tv_usec;
+ if (d->tv_usec < 0)
+ {
+ d->tv_usec += 1000000;
+ d->tv_sec -= 1;
+ if (d->tv_sec < 0) /* ??? -- BSD/OS does this */
+ {
+ d->tv_sec = 0;
+ d->tv_usec = 0;
+ }
+ }
+ return d;
+}
+
+struct timeval *
+addtimeval (d, t1, t2)
+ struct timeval *d, *t1, *t2;
+{
+ d->tv_sec = t1->tv_sec + t2->tv_sec;
+ d->tv_usec = t1->tv_usec + t2->tv_usec;
+ if (d->tv_usec >= 1000000)
+ {
+ d->tv_usec -= 1000000;
+ d->tv_sec += 1;
+ }
+ return d;
+}
+
+/* Do "cpu = ((user + sys) * 10000) / real;" with timevals.
+ Barely-tested code from Deven T. Corzine <deven@ties.org>. */
+int
+timeval_to_cpu (rt, ut, st)
+ struct timeval *rt, *ut, *st; /* real, user, sys */
+{
+ struct timeval t1, t2;
+ register int i;
+
+ addtimeval (&t1, ut, st);
+ t2.tv_sec = rt->tv_sec;
+ t2.tv_usec = rt->tv_usec;
+
+ for (i = 0; i < 6; i++)
+ {
+ if ((t1.tv_sec > 99999999) || (t2.tv_sec > 99999999))
+ break;
+ t1.tv_sec *= 10;
+ t1.tv_sec += t1.tv_usec / 100000;
+ t1.tv_usec *= 10;
+ t1.tv_usec %= 1000000;
+ t2.tv_sec *= 10;
+ t2.tv_sec += t2.tv_usec / 100000;
+ t2.tv_usec *= 10;
+ t2.tv_usec %= 1000000;
+ }
+ for (i = 0; i < 4; i++)
+ {
+ if (t1.tv_sec < 100000000)
+ t1.tv_sec *= 10;
+ else
+ t2.tv_sec /= 10;
+ }
+
+ return ((t2.tv_sec == 0) ? 0 : t1.tv_sec / t2.tv_sec);
+}
+
+/* Convert a pointer to a struct timeval to seconds and thousandths of a
+ second, returning the values in *SP and *SFP, respectively. This does
+ rounding on the fractional part, not just truncation to three places. */
+void
+timeval_to_secs (tvp, sp, sfp)
+ struct timeval *tvp;
+ long *sp;
+ int *sfp;
+{
+ int rest;
+
+ *sp = tvp->tv_sec;
+
+ *sfp = tvp->tv_usec % 1000000; /* pretty much a no-op */
+ rest = *sfp % 1000;
+ *sfp = (*sfp * 1000) / 1000000;
+ if (rest >= 500)
+ *sfp += 1;
+
+ /* Sanity check */
+ if (*sfp >= 1000)
+ {
+ *sp += 1;
+ *sfp -= 1000;
+ }
+}
+
+/* Print the contents of a struct timeval * in a standard way to stdio
+ stream FP. */
+void
+print_timeval (fp, tvp)
+ FILE *fp;
+ struct timeval *tvp;
+{
+ int minutes, seconds_fraction;
+ long seconds;
+
+ timeval_to_secs (tvp, &seconds, &seconds_fraction);
+
+ minutes = seconds / 60;
+ seconds %= 60;
+
+ fprintf (fp, "%0dm%0ld.%03ds", minutes, seconds, seconds_fraction);
+}
+#endif /* HAVE_TIMEVAL */
diff --git a/lib/sh/vprint.c b/lib/sh/vprint.c
index 63ea3bf..929bdbc 100644
--- a/lib/sh/vprint.c
+++ b/lib/sh/vprint.c
@@ -6,7 +6,7 @@ This file is part of GNU Bash, the Bourne Again SHell.
Bash is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 1, or (at your option) any later
+Software Foundation; either version 2, or (at your option) any later
version.
Bash is distributed in the hope that it will be useful, but WITHOUT ANY
@@ -16,7 +16,7 @@ for more details.
You should have received a copy of the GNU General Public License along
with Bash; see the file COPYING. If not, write to the Free Software
-Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
+Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
#include <config.h>
diff --git a/lib/sh/zread.c b/lib/sh/zread.c
new file mode 100644
index 0000000..0b23b38
--- /dev/null
+++ b/lib/sh/zread.c
@@ -0,0 +1,127 @@
+/* Copyright (C) 1999 Free Software Foundation, Inc.
+
+ This file is part of GNU Bash, the Bourne Again SHell.
+
+ Bash is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 2, or (at your option) any later
+ version.
+
+ Bash is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with Bash; see the file COPYING. If not, write to the Free Software
+ Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
+
+#include <config.h>
+
+#include <sys/types.h>
+
+#if defined (HAVE_UNISTD_H)
+# include <unistd.h>
+#endif
+
+#include <errno.h>
+
+#if !defined (errno)
+extern int errno;
+#endif
+
+#ifndef SEEK_CUR
+# define SEEK_CUR 1
+#endif
+
+/* Read LEN bytes from FD into BUF. Retry the read on EINTR. Any other
+ error causes the loop to break. */
+int
+zread (fd, buf, len)
+ int fd;
+ char *buf;
+ size_t len;
+{
+ int r;
+
+ while ((r = read (fd, buf, len)) < 0 && errno == EINTR)
+ ;
+ return r;
+}
+
+/* Read LEN bytes from FD into BUF. Retry the read on EINTR, up to three
+ interrupts. Any other error causes the loop to break. */
+
+#ifdef NUM_INTR
+# undef NUM_INTR
+#endif
+#define NUM_INTR 3
+
+int
+zread1 (fd, buf, len)
+ int fd;
+ char *buf;
+ size_t len;
+{
+ int r, nintr;
+
+ for (nintr = 0; ; )
+ {
+ r = read (fd, buf, len);
+ if (r >= 0)
+ return r;
+ if (r == -1 && errno == EINTR)
+ {
+ if (++nintr > NUM_INTR)
+ return -1;
+ continue;
+ }
+ return r;
+ }
+}
+
+/* Read one character from FD and return it in CP. Return values are as
+ in read(2). This does some local buffering to avoid many one-character
+ calls to read(2), like those the `read' builtin performs. */
+
+static unsigned char lbuf[128];
+static int lind, lused;
+
+int
+zreadc (fd, cp)
+ int fd;
+ char *cp;
+{
+ int r;
+
+ if (lind == lused || lused == 0)
+ {
+ lused = zread (fd, lbuf, sizeof (lbuf));
+ lind = 0;
+ if (lused <= 0)
+ return (lused);
+ }
+ if (cp)
+ *cp = (char)lbuf[lind++];
+ return 1;
+}
+
+void
+zreset ()
+{
+ lind = lused = 0;
+}
+
+/* Sync the seek pointer for FD so that the kernel's idea of the last char
+ read is the last char returned by zreadc. */
+void
+zsyncfd (fd)
+ int fd;
+{
+ int off;
+
+ off = lused - lind;
+ if (off > 0)
+ lseek (fd, -off, SEEK_CUR);
+ lused = lind = 0;
+}
diff --git a/lib/sh/zwrite.c b/lib/sh/zwrite.c
new file mode 100644
index 0000000..25550f8
--- /dev/null
+++ b/lib/sh/zwrite.c
@@ -0,0 +1,61 @@
+/* Copyright (C) 1999 Free Software Foundation, Inc.
+
+ This file is part of GNU Bash, the Bourne Again SHell.
+
+ Bash is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 2, or (at your option) any later
+ version.
+
+ Bash is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with Bash; see the file COPYING. If not, write to the Free Software
+ Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
+
+#include <config.h>
+
+#include <sys/types.h>
+
+#if defined (HAVE_UNISTD_H)
+# include <unistd.h>
+#endif
+
+#include <errno.h>
+
+#if !defined (errno)
+extern int errno;
+#endif
+
+/* Write NB bytes from BUF to file descriptor FD, retrying the write if
+ it is interrupted. We retry three times if we get a zero-length
+ write. Any other signal causes this function to return prematurely. */
+int
+zwrite (fd, buf, nb)
+ int fd;
+ unsigned char *buf;
+ size_t nb;
+{
+ int n, i, nt;
+
+ for (n = nb, nt = 0;;)
+ {
+ i = write (fd, buf, n);
+ if (i > 0)
+ {
+ n -= i;
+ if (n <= 0)
+ return nb;
+ }
+ else if (i == 0)
+ {
+ if (++nt > 3)
+ return (nb - n);
+ }
+ else if (errno != EINTR)
+ return -1;
+ }
+}