diff options
author | Jari Aalto <jari.aalto@cante.net> | 2004-07-27 13:29:18 +0000 |
---|---|---|
committer | Jari Aalto <jari.aalto@cante.net> | 2009-09-12 16:46:56 +0000 |
commit | b80f6443b6b7b620c7272664c66ecb0b120a0998 (patch) | |
tree | 9f71c98d8fe8fa0f41d95e1eb4227f32a09d43ca /lib/sh | |
parent | 7117c2d221b2aed4ede8600f6a36b7c1454b4f55 (diff) | |
download | bash-b80f6443b6b7b620c7272664c66ecb0b120a0998.tar.gz |
Imported from ../bash-3.0.tar.gz.
Diffstat (limited to 'lib/sh')
-rw-r--r-- | lib/sh/Makefile.in | 53 | ||||
-rw-r--r-- | lib/sh/fmtulong.c | 7 | ||||
-rw-r--r-- | lib/sh/getcwd.c | 4 | ||||
-rw-r--r-- | lib/sh/getenv.c | 4 | ||||
-rw-r--r-- | lib/sh/mailstat.c | 2 | ||||
-rw-r--r-- | lib/sh/netconn.c | 2 | ||||
-rw-r--r-- | lib/sh/netopen.c | 10 | ||||
-rw-r--r-- | lib/sh/pathcanon.c | 8 | ||||
-rw-r--r-- | lib/sh/pathphys.c | 48 | ||||
-rw-r--r-- | lib/sh/shmatch.c | 121 | ||||
-rw-r--r-- | lib/sh/shquote.c | 13 | ||||
-rw-r--r-- | lib/sh/snprintf.c | 9 | ||||
-rw-r--r-- | lib/sh/strftime.c | 2 | ||||
-rw-r--r-- | lib/sh/strstr.c | 122 | ||||
-rw-r--r-- | lib/sh/strtrans.c | 21 | ||||
-rw-r--r-- | lib/sh/tmpfile.c | 8 |
16 files changed, 393 insertions, 41 deletions
diff --git a/lib/sh/Makefile.in b/lib/sh/Makefile.in index 468899d2..c375c1de 100644 --- a/lib/sh/Makefile.in +++ b/lib/sh/Makefile.in @@ -18,13 +18,28 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA. +PACKAGE = @PACKAGE_NAME@ +VERSION = @PACKAGE_VERSION@ + +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_VERSION = @PACKAGE_VERSION@ + srcdir = @srcdir@ VPATH = .:@srcdir@ topdir = @top_srcdir@ BUILD_DIR = @BUILD_DIR@ +LIBBUILD = ${BUILD_DIR}/lib + BASHINCDIR = ${topdir}/include +INTL_LIBSRC = ${topdir}/lib/intl +INTL_BUILDDIR = ${LIBBUILD}/intl +INTL_INC = @INTL_INC@ +LIBINTL_H = @LIBINTL_H@ + INSTALL = @INSTALL@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_DATA = @INSTALL_DATA@ @@ -49,7 +64,7 @@ PROFILE_FLAGS = @PROFILE_FLAGS@ DEFS = @DEFS@ LOCAL_DEFS = @LOCAL_DEFS@ -INCLUDES = -I. -I../.. -I$(topdir) -I$(topdir)/lib -I$(BASHINCDIR) -I$(srcdir) +INCLUDES = -I. -I../.. -I$(topdir) -I$(topdir)/lib -I$(BASHINCDIR) -I$(srcdir) $(INTL_INC) CCFLAGS = ${PROFILE_FLAGS} ${INCLUDES} $(DEFS) $(LOCAL_DEFS) $(LOCAL_CFLAGS) \ $(CFLAGS) $(CPPFLAGS) @@ -71,8 +86,8 @@ CSOURCES = clktck.c clock.c getcwd.c getenv.c oslib.c setlinebuf.c \ inet_aton.c netconn.c netopen.c strpbrk.c timeval.c makepath.c \ pathcanon.c pathphys.c tmpfile.c stringlist.c stringvec.c spell.c \ shquote.c strtrans.c strindex.c snprintf.c mailstat.c \ - fmtulong.c fmtullong.c fmtumax.c \ - strtoll.c strtoull.c strtoimax.c strtoumax.c memset.c \ + fmtulong.c fmtullong.c fmtumax.c shmatch.c \ + strtoll.c strtoull.c strtoimax.c strtoumax.c memset.c strstr.c \ mktime.c strftime.c xstrchr.c zcatfd.c # The header files for this library. @@ -81,7 +96,7 @@ HSOURCES = # The object files contained in $(LIBRARY_NAME) LIBOBJS = @LIBOBJS@ OBJECTS = clktck.o clock.o getenv.o oslib.o setlinebuf.o \ - itos.o zread.o zwrite.o shtty.o \ + itos.o zread.o zwrite.o shtty.o shmatch.o \ netconn.o netopen.o timeval.o makepath.o pathcanon.o \ pathphys.o tmpfile.o stringlist.o stringvec.o spell.o shquote.o \ strtrans.o strindex.o snprintf.o mailstat.o fmtulong.o \ @@ -113,6 +128,9 @@ mostlyclean: clean # Dependencies +${BUILD_DIR}/version.h: ${BUILD_DIR}/config.h ${BUILD_DIR}/Makefile Makefile + -( cd ${BUILD_DIR} && ${MAKE} ${MFLAGS} version.h ) + # rules for losing makes, like SunOS clktck.o: clktck.c clock.o: clock.c @@ -231,7 +249,8 @@ getenv.o: ${topdir}/general.h ${topdir}/bashtypes.h ${topdir}/variables.h ${topd 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 +getenv.o: ${BUILD_DIR}/pathnames.h ${topdir}/externs.h +getenv.o: ${BUILD_DIR}/version.h inet_aton.o: ${topdir}/bashansi.h ${BASHINCDIR}/ansi_stdlib.h inet_aton.o: ${BASHINCDIR}/stdc.h @@ -243,7 +262,7 @@ itos.o: ${topdir}/general.h ${topdir}/bashtypes.h ${topdir}/variables.h ${topdir 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 +itos.o: ${BUILD_DIR}/pathnames.h ${topdir}/externs.h ${BUILD_DIR}/version.h makepath.o: ${topdir}/bashansi.h ${BASHINCDIR}/ansi_stdlib.h makepath.o: ${topdir}/shell.h ${topdir}/syntax.h ${topdir}/bashjmp.h ${BASHINCDIR}/posixjmp.h @@ -252,7 +271,7 @@ makepath.o: ${topdir}/general.h ${topdir}/bashtypes.h ${topdir}/variables.h ${to makepath.o: ${topdir}/array.h ${topdir}/hashlib.h ${topdir}/quit.h makepath.o: ${topdir}/unwind_prot.h ${topdir}/dispose_cmd.h makepath.o: ${topdir}/make_cmd.h ${topdir}/subst.h ${topdir}/sig.h -makepath.o: ${topdir}/pathnames.h ${topdir}/externs.h +makepath.o: ${BUILD_DIR}/pathnames.h ${topdir}/externs.h ${BUILD_DIR}/version.h netconn.o: ${BASHINCDIR}/posixstat.h ${BASHINCDIR}/filecntl.h netconn.o: ${topdir}/bashtypes.h @@ -264,7 +283,8 @@ netopen.o: ${topdir}/general.h ${topdir}/bashtypes.h ${topdir}/variables.h ${top netopen.o: ${topdir}/array.h ${topdir}/hashlib.h ${topdir}/quit.h netopen.o: ${topdir}/unwind_prot.h ${topdir}/dispose_cmd.h netopen.o: ${topdir}/make_cmd.h ${topdir}/subst.h ${topdir}/sig.h -netopen.o: ${topdir}/pathnames.h ${topdir}/externs.h +netopen.o: ${BUILD_DIR}/pathnames.h ${topdir}/externs.h ${BUILD_DIR}/version.h +netopen.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h oslib.o: ${topdir}/bashtypes.h ${topdir}/bashansi.h ${BASHINCDIR}/maxpath.h oslib.o: ${topdir}/shell.h ${topdir}/syntax.h ${topdir}/bashjmp.h ${BASHINCDIR}/posixjmp.h @@ -273,7 +293,7 @@ oslib.o: ${topdir}/general.h ${topdir}/bashtypes.h ${topdir}/variables.h ${topdi 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: ${BUILD_DIR}/pathnames.h ${topdir}/externs.h ${BUILD_DIR}/version.h oslib.o: ${BASHINCDIR}/posixstat.h ${BASHINCDIR}/filecntl.h oslib.o: ${BASHINCDIR}/ansi_stdlib.h ${BASHINCDIR}/chartypes.h @@ -284,7 +304,7 @@ pathcanon.o: ${topdir}/general.h ${topdir}/bashtypes.h ${topdir}/variables.h ${t pathcanon.o: ${topdir}/array.h ${topdir}/hashlib.h ${topdir}/quit.h pathcanon.o: ${topdir}/unwind_prot.h ${topdir}/dispose_cmd.h pathcanon.o: ${topdir}/make_cmd.h ${topdir}/subst.h ${topdir}/sig.h -pathcanon.o: ${topdir}/pathnames.h ${topdir}/externs.h +pathcanon.o: ${BUILD_DIR}/pathnames.h ${topdir}/externs.h ${BUILD_DIR}/version.h pathcanon.o: ${BASHINCDIR}/posixstat.h ${BASHINCDIR}/filecntl.h pathcanon.o: ${BASHINCDIR}/ansi_stdlib.h ${BASHINCDIR}/chartypes.h @@ -295,7 +315,7 @@ pathphys.o: ${topdir}/general.h ${topdir}/bashtypes.h ${topdir}/variables.h ${to pathphys.o: ${topdir}/array.h ${topdir}/hashlib.h ${topdir}/quit.h pathphys.o: ${topdir}/unwind_prot.h ${topdir}/dispose_cmd.h pathphys.o: ${topdir}/make_cmd.h ${topdir}/subst.h ${topdir}/sig.h -pathphys.o: ${topdir}/pathnames.h ${topdir}/externs.h +pathphys.o: ${BUILD_DIR}/pathnames.h ${topdir}/externs.h ${BUILD_DIR}/version.h pathphys.o: ${BASHINCDIR}/posixstat.h ${BASHINCDIR}/filecntl.h pathphys.o: ${BASHINCDIR}/ansi_stdlib.h ${BASHINCDIR}/chartypes.h @@ -329,7 +349,7 @@ strerror.o: ${topdir}/general.h ${topdir}/bashtypes.h ${topdir}/variables.h ${to 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 +strerror.o: ${BUILD_DIR}/pathnames.h ${topdir}/externs.h ${BUILD_DIR}/version.h strindex.o: ${BASHINCDIR}/stdc.h ${topdir}/bashansi.h strindex.o: ${BASHINCDIR}/ansi_stdlib.h ${BASHINCDIR}/chartypes.h @@ -341,7 +361,7 @@ stringlist.o: ${topdir}/general.h ${topdir}/bashtypes.h ${topdir}/variables.h ${ stringlist.o: ${topdir}/array.h ${topdir}/hashlib.h ${topdir}/quit.h stringlist.o: ${topdir}/unwind_prot.h ${topdir}/dispose_cmd.h stringlist.o: ${topdir}/make_cmd.h ${topdir}/subst.h ${topdir}/sig.h -stringlist.o: ${topdir}/pathnames.h ${topdir}/externs.h +stringlist.o: ${BUILD_DIR}/pathnames.h ${topdir}/externs.h ${BUILD_DIR}/version.h stringvec.o: ${topdir}/bashansi.h ${BASHINCDIR}/chartypes.h stringvec.o: ${topdir}/shell.h ${topdir}/syntax.h ${topdir}/bashjmp.h ${BASHINCDIR}/posixjmp.h @@ -350,7 +370,7 @@ stringvec.o: ${topdir}/general.h ${topdir}/bashtypes.h ${topdir}/variables.h ${t stringvec.o: ${topdir}/array.h ${topdir}/hashlib.h ${topdir}/quit.h stringvec.o: ${topdir}/unwind_prot.h ${topdir}/dispose_cmd.h stringvec.o: ${topdir}/make_cmd.h ${topdir}/subst.h ${topdir}/sig.h -stringvec.o: ${topdir}/pathnames.h ${topdir}/externs.h +stringvec.o: ${BUILD_DIR}/pathnames.h ${topdir}/externs.h ${BUILD_DIR}/version.h strpbrk.o: ${BASHINCDIR}/stdc.h @@ -385,7 +405,7 @@ strtrans.o: ${topdir}/general.h ${topdir}/bashtypes.h ${topdir}/variables.h ${to strtrans.o: ${topdir}/array.h ${topdir}/hashlib.h ${topdir}/quit.h strtrans.o: ${topdir}/unwind_prot.h ${topdir}/dispose_cmd.h strtrans.o: ${topdir}/make_cmd.h ${topdir}/subst.h ${topdir}/sig.h -strtrans.o: ${topdir}/pathnames.h ${topdir}/externs.h +strtrans.o: ${BUILD_DIR}/pathnames.h ${topdir}/externs.h ${BUILD_DIR}/version.h times.o: ${BASHINCDIR}/systimes.h times.o: ${BASHINCDIR}/posixtime.h @@ -410,18 +430,21 @@ fmtulong.o: ${BASHINCDIR}/ansi_stdlib.h fmtulong.o: ${BASHINCDIR}/chartypes.h fmtulong.o: ${BASHINCDIR}/stdc.h fmtulong.o: ${BASHINCDIR}/typemax.h +fmtulong.o: ${topdir}/bashintl.h ${LIBINTL_H} ${BASHINCDIR}/gettext.h fmtullong.o: ${topdir}/bashansi.h fmtullong.o: ${BASHINCDIR}/ansi_stdlib.h fmtullong.o: ${BASHINCDIR}/chartypes.h fmtullong.o: ${BASHINCDIR}/stdc.h fmtullong.o: ${BASHINCDIR}/typemax.h +fmtullong.o: ${topdir}/bashintl.h ${LIBINTL_H} ${BASHINCDIR}/gettext.h fmtumax.o: ${topdir}/bashansi.h fmtumax.o: ${BASHINCDIR}/ansi_stdlib.h fmtumax.o: ${BASHINCDIR}/chartypes.h fmtumax.o: ${BASHINCDIR}/stdc.h fmtumax.o: ${BASHINCDIR}/typemax.h +fmtumax.o: ${topdir}/bashintl.h ${LIBINTL_H} ${BASHINCDIR}/gettext.h xstrchr.o: ${topdir}/bashansi.h xstrchr.o: ${BASHINCDIR}/ansi_stdlib.h diff --git a/lib/sh/fmtulong.c b/lib/sh/fmtulong.c index dc313be9..43fdffda 100644 --- a/lib/sh/fmtulong.c +++ b/lib/sh/fmtulong.c @@ -38,9 +38,14 @@ #ifdef HAVE_STDINT_H # include <stdint.h> #endif +#ifdef HAVE_INTTYPES_H +# include <inttypes.h> +#endif #include <chartypes.h> #include <errno.h> +#include <bashintl.h> + #include "stdc.h" #include <typemax.h> @@ -93,7 +98,7 @@ fmtulong (ui, base, buf, len, flags) if (base < 2 || base > 64) { #if 1 - strncpy (buf, "invalid base", len - 1); + strncpy (buf, _("invalid base"), len - 1); buf[len] = '\0'; errno = EINVAL; return (p = buf); diff --git a/lib/sh/getcwd.c b/lib/sh/getcwd.c index 0c8b1da8..cd724f6f 100644 --- a/lib/sh/getcwd.c +++ b/lib/sh/getcwd.c @@ -22,6 +22,10 @@ #if !defined (HAVE_GETCWD) +#if !defined (__GNUC__) && !defined (HAVE_ALLOCA_H) && defined (_AIX) + #pragma alloca +#endif /* _AIX && RISC6000 && !__GNUC__ */ + #include <bashtypes.h> #include <errno.h> diff --git a/lib/sh/getenv.c b/lib/sh/getenv.c index 028afb15..a7dfb186 100644 --- a/lib/sh/getenv.c +++ b/lib/sh/getenv.c @@ -115,7 +115,7 @@ putenv (str) return -1; } - offset = assignment (str); + offset = assignment (str, 0); if (str[offset] != '=') { errno = EINVAL; @@ -169,7 +169,7 @@ setenv (name, value, rewrite) } var = 0; - v = value; + v = (char *)value; /* some compilers need explicit cast */ /* XXX - should we worry about readonly here? */ if (rewrite == 0) var = find_variable (name); diff --git a/lib/sh/mailstat.c b/lib/sh/mailstat.c index 8005252a..03782e78 100644 --- a/lib/sh/mailstat.c +++ b/lib/sh/mailstat.c @@ -149,7 +149,7 @@ mailstat(path, st) closedir(dd); } - if (atime) +/* if (atime) */ /* Set atime even if cur/ is empty */ st_ret.st_atime = atime; if (mtime) st_ret.st_mtime = mtime; diff --git a/lib/sh/netconn.c b/lib/sh/netconn.c index f412cb02..d05aef55 100644 --- a/lib/sh/netconn.c +++ b/lib/sh/netconn.c @@ -22,7 +22,7 @@ #include <config.h> #include <bashtypes.h> -#ifndef _MINIX +#if ! defined(_MINIX) && defined (HAVE_SYS_FILE_H) # include <sys/file.h> #endif #include <posixstat.h> diff --git a/lib/sh/netopen.c b/lib/sh/netopen.c index 4197db1b..aaf0c475 100644 --- a/lib/sh/netopen.c +++ b/lib/sh/netopen.c @@ -51,6 +51,8 @@ #endif #include <bashansi.h> +#include <bashintl.h> + #include <errno.h> #include <shell.h> @@ -153,14 +155,14 @@ _netopen4(host, serv, typ) if (_getaddr(host, &ina) == 0) { - internal_error ("%s: host unknown", host); + internal_error (_("%s: host unknown"), host); errno = EINVAL; return -1; } if (_getserv(serv, typ, &p) == 0) { - internal_error("%s: invalid service", serv); + internal_error(_("%s: invalid service"), serv); errno = EINVAL; return -1; } @@ -291,7 +293,7 @@ netopen (path) t = strchr (s, '/'); if (t == 0) { - internal_error ("%s: bad network path specification", path); + internal_error (_("%s: bad network path specification"), path); return -1; } *t++ = '\0'; @@ -331,7 +333,7 @@ int netopen (path) char *path; { - internal_error ("network operations not supported"); + internal_error (_("network operations not supported")); return -1; } diff --git a/lib/sh/pathcanon.c b/lib/sh/pathcanon.c index d74f99c0..88929540 100644 --- a/lib/sh/pathcanon.c +++ b/lib/sh/pathcanon.c @@ -34,9 +34,14 @@ #include <bashansi.h> #include <stdio.h> #include <chartypes.h> +#include <errno.h> #include "shell.h" +#if !defined (errno) +extern int errno; +#endif + #if defined (__CYGWIN__) #include <sys/cygwin.h> @@ -70,9 +75,10 @@ static int _path_isdir (path) char *path; { - int l; + int l, x; struct stat sb; + /* This should leave errno set to the correct value. */ l = stat (path, &sb) == 0 && S_ISDIR (sb.st_mode); #if defined (__CYGWIN__) if (l == 0) diff --git a/lib/sh/pathphys.c b/lib/sh/pathphys.c index df692043..4d6304ce 100644 --- a/lib/sh/pathphys.c +++ b/lib/sh/pathphys.c @@ -68,7 +68,7 @@ _path_readlink (path, buf, bufsiz) /* * Return PATH with all symlinks expanded in newly-allocated memory. - * This always gets a full pathname. + * This always gets an absolute pathname. */ char * @@ -80,11 +80,26 @@ sh_physpath (path, flags) char *result, *p, *q, *qsave, *qbase, *workpath; int double_slash_path, linklen, nlink; + linklen = strlen (path); + +#if 0 + /* First sanity check -- punt immediately if the name is too long. */ + if (linklen >= PATH_MAX) + return (savestring (path)); +#endif + nlink = 0; q = result = (char *)xmalloc (PATH_MAX + 1); - workpath = (char *)xmalloc (PATH_MAX + 1); - strcpy (workpath, path); + /* Even if we get something longer than PATH_MAX, we might be able to + shorten it, so we try. */ + if (linklen >= PATH_MAX) + workpath = savestring (path); + else + { + workpath = (char *)xmalloc (PATH_MAX + 1); + strcpy (workpath, path); + } /* This always gets an absolute pathname. */ @@ -133,7 +148,19 @@ sh_physpath (path, flags) if (q != qbase) *q++ = DIRSEP; while (*p && (ISDIRSEP(*p) == 0)) - *q++ = *p++; + { + if (q - result >= PATH_MAX) + { +#ifdef ENAMETOOLONG + errno = ENAMETOOLONG; +#else + errno = EINVAL; +#endif + goto error; + } + + *q++ = *p++; + } *q = '\0'; @@ -151,6 +178,8 @@ sh_physpath (path, flags) { #ifdef ELOOP errno = ELOOP; +#else + errno = EINVAL; #endif error: free (result); @@ -160,6 +189,17 @@ error: linkbuf[linklen] = '\0'; + /* If the new path length would overrun PATH_MAX, punt now. */ + if ((strlen (p) + linklen + 2) >= PATH_MAX) + { +#ifdef ENAMETOOLONG + errno = ENAMETOOLONG; +#else + errno = EINVAL; +#endif + goto error; + } + /* Form the new pathname by copying the link value to a temporary buffer and appending the rest of `workpath'. Reset p to point to the start of the rest of the path. If the link value is an diff --git a/lib/sh/shmatch.c b/lib/sh/shmatch.c new file mode 100644 index 00000000..18292ae2 --- /dev/null +++ b/lib/sh/shmatch.c @@ -0,0 +1,121 @@ +/* Copyright (C) 2003 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. */ + +/* + * shmatch.c -- shell interface to posix regular expression matching. + */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#if defined (HAVE_POSIX_REGEXP) + +#ifdef HAVE_UNISTD_H +# include <unistd.h> +#endif + +#include "bashansi.h" + +#include <stdio.h> +#include <regex.h> + +#include "shell.h" +#include "variables.h" +#include "externs.h" + +extern int glob_ignore_case; + +int +sh_regmatch (string, pattern, flags) + const char *string; + const char *pattern; + int flags; +{ + regex_t regex = { 0 }; + regmatch_t *matches; + int rflags; +#if defined (ARRAY_VARS) + SHELL_VAR *rematch; + ARRAY *amatch; + int subexp_ind; + char *subexp_str; + int subexp_len; +#endif + int result; + + +#if defined (ARRAY_VARS) + rematch = (SHELL_VAR *)NULL; +#endif + + rflags = REG_EXTENDED; + if (glob_ignore_case) + rflags |= REG_ICASE; +#if !defined (ARRAY_VARS) + rflags |= REG_NOSUB; +#endif + + if (regcomp (®ex, pattern, rflags)) + return 2; /* flag for printing a warning here. */ + +#if defined (ARRAY_VARS) + matches = (regmatch_t *)malloc (sizeof (regmatch_t) * (regex.re_nsub + 1)); +#else + matches = NULL; +#endif + + if (regexec (®ex, string, regex.re_nsub + 1, matches, 0)) + result = EXECUTION_FAILURE; + else + result = EXECUTION_SUCCESS; /* match */ + +#if defined (ARRAY_VARS) + subexp_len = strlen (string) + 10; + subexp_str = malloc (subexp_len + 1); + + /* Store the parenthesized subexpressions in the array BASH_REMATCH. + Element 0 is the portion that matched the entire regexp. Element 1 + is the part that matched the first subexpression, and so on. */ + unbind_variable ("BASH_REMATCH"); + rematch = make_new_array_variable ("BASH_REMATCH"); + amatch = array_cell (rematch); + + if ((flags & SHMAT_SUBEXP) && result == EXECUTION_SUCCESS && subexp_str) + { + for (subexp_ind = 0; subexp_ind <= regex.re_nsub; subexp_ind++) + { + memset (subexp_str, 0, subexp_len); + strncpy (subexp_str, string + matches[subexp_ind].rm_so, + matches[subexp_ind].rm_eo - matches[subexp_ind].rm_so); + array_insert (amatch, subexp_ind, subexp_str); + } + } + + VSETATTR (rematch, att_readonly); + + free (subexp_str); + free (matches); +#endif /* ARRAY_VARS */ + + regfree (®ex); + + return result; +} + +#endif /* HAVE_POSIX_REGEXP */ diff --git a/lib/sh/shquote.c b/lib/sh/shquote.c index 713f4819..aac2d349 100644 --- a/lib/sh/shquote.c +++ b/lib/sh/shquote.c @@ -83,6 +83,8 @@ sh_double_quote (string) { if (sh_syntaxtab[c] & CBSDQUOTE) *r++ = '\\'; + else if (c == CTLESC || c == CTLNUL) + *r++ = CTLESC; /* could be '\\'? */ *r++ = c; } @@ -94,7 +96,8 @@ sh_double_quote (string) } /* Remove backslashes that are quoting characters that are special between - double quotes. Return a new string. */ + double quotes. Return a new string. XXX - should this handle CTLESC + and CTLNUL? */ char * sh_un_double_quote (string) char *string; @@ -158,6 +161,11 @@ sh_backslash_quote (string) *r++ = c; break; #endif + case CTLESC: case CTLNUL: /* internal quoting characters */ + *r++ = CTLESC; /* could be '\\'? */ + *r++ = c; + break; + case '#': /* comment char */ if (s == string) *r++ = '\\'; @@ -188,6 +196,9 @@ sh_backslash_quote_for_double_quotes (string) { if (sh_syntaxtab[c] & CBSDQUOTE) *r++ = '\\'; + /* I should probably add flags for these to sh_syntaxtab[] */ + else if (c == CTLESC || c == CTLNUL) + *r++ = CTLESC; /* could be '\\'? */ *r++ = c; } diff --git a/lib/sh/snprintf.c b/lib/sh/snprintf.c index 7669576c..b79b41fb 100644 --- a/lib/sh/snprintf.c +++ b/lib/sh/snprintf.c @@ -45,10 +45,11 @@ /* * Currently doesn't handle (and bash/readline doesn't use): - * *M$ width, precision specifications - * %N$ numbered argument conversions - * inf, nan floating values imperfect (if isinf(), isnan() not in libc) - * support for `F' is imperfect, since underlying printf may not handle it + * * *M$ width, precision specifications + * * %N$ numbered argument conversions + * * inf, nan floating values imperfect (if isinf(), isnan() not in libc) + * * support for `F' is imperfect with ldfallback(), since underlying + * printf may not handle it -- should ideally have another autoconf test */ #define FLOATING_POINT diff --git a/lib/sh/strftime.c b/lib/sh/strftime.c index 253d1df4..4cb542f5 100644 --- a/lib/sh/strftime.c +++ b/lib/sh/strftime.c @@ -95,7 +95,7 @@ static int iso8601wknum(const struct tm *timeptr); #if !defined(OS2) && !defined(MSDOS) && defined(HAVE_TZNAME) extern char *tzname[2]; extern int daylight; -#if defined(SOLARIS) || defined(mips) +#if defined(SOLARIS) || defined(mips) || defined (M_UNIX) extern long int timezone, altzone; #else extern int timezone, altzone; diff --git a/lib/sh/strstr.c b/lib/sh/strstr.c new file mode 100644 index 00000000..c41e9034 --- /dev/null +++ b/lib/sh/strstr.c @@ -0,0 +1,122 @@ +/* Copyright (C) 1994, 1999 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +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. */ + +/* + * My personal strstr() implementation that beats most other algorithms. + * Until someone tells me otherwise, I assume that this is the + * fastest implementation of strstr() in C. + * I deliberately chose not to comment it. You should have at least + * as much fun trying to understand it, as I had to write it :-). + * + * Stephen R. van den Berg, berg@pool.informatik.rwth-aachen.de */ + +#if HAVE_CONFIG_H +# include <config.h> +#endif + +#if defined _LIBC || defined HAVE_STRING_H +# include <string.h> +#endif +#include <sys/types.h> + +typedef unsigned chartype; + +#undef strstr + +char * +strstr (const char *phaystack, const char *pneedle) +{ + register const unsigned char *haystack, *needle; + register chartype b, c; + + haystack = (const unsigned char *) phaystack; + needle = (const unsigned char *) pneedle; + + b = *needle; + if (b != '\0') + { + haystack--; /* possible ANSI violation */ + do + { + c = *++haystack; + if (c == '\0') + goto ret0; + } + while (c != b); + + c = *++needle; + if (c == '\0') + goto foundneedle; + ++needle; + goto jin; + + for (;;) + { + register chartype a; + register const unsigned char *rhaystack, *rneedle; + + do + { + a = *++haystack; + if (a == '\0') + goto ret0; + if (a == b) + break; + a = *++haystack; + if (a == '\0') + goto ret0; +shloop:; } + while (a != b); + +jin: a = *++haystack; + if (a == '\0') + goto ret0; + + if (a != c) + goto shloop; + + rhaystack = haystack-- + 1; + rneedle = needle; + a = *rneedle; + + if (*rhaystack == a) + do + { + if (a == '\0') + goto foundneedle; + ++rhaystack; + a = *++needle; + if (*rhaystack != a) + break; + if (a == '\0') + goto foundneedle; + ++rhaystack; + a = *++needle; + } + while (*rhaystack == a); + + needle = rneedle; /* took the register-poor approach */ + + if (a == '\0') + break; + } + } +foundneedle: + return (char*) haystack; +ret0: + return 0; +} diff --git a/lib/sh/strtrans.c b/lib/sh/strtrans.c index 741927c6..e264e3db 100644 --- a/lib/sh/strtrans.c +++ b/lib/sh/strtrans.c @@ -92,10 +92,27 @@ ansicstr (string, len, flags, sawc, rlen) c &= 0xFF; break; case 'x': /* Hex digit -- non-ANSI */ + if ((flags & 2) && *s == '{') + { + flags |= 16; /* internal flag value */ + s++; + } + /* Consume at least two hex characters */ for (temp = 2, c = 0; ISXDIGIT ((unsigned char)*s) && temp--; s++) c = (c * 16) + HEXVALUE (*s); + /* DGK says that after a `\x{' ksh93 consumes ISXDIGIT chars + until a non-xdigit or `}', so potentially more than two + chars are consumed. */ + if (flags & 16) + { + for ( ; ISXDIGIT ((unsigned char)*s); s++) + c = (c * 16) + HEXVALUE (*s); + flags &= ~16; + if (*s == '}') + s++; + } /* \x followed by non-hex digits is passed through unchanged */ - if (temp == 2) + else if (temp == 2) { *r++ = '\\'; c = 'x'; @@ -104,7 +121,7 @@ ansicstr (string, len, flags, sawc, rlen) break; case '\\': break; - case '\'': + case '\'': case '"': case '?': if (flags & 1) *r++ = '\\'; break; diff --git a/lib/sh/tmpfile.c b/lib/sh/tmpfile.c index e28f94d0..fb7b732d 100644 --- a/lib/sh/tmpfile.c +++ b/lib/sh/tmpfile.c @@ -62,20 +62,20 @@ get_sys_tmpdir () #ifdef P_tmpdir sys_tmpdir = P_tmpdir; - if (stat (sys_tmpdir, &sb) == 0) + if (file_iswdir (sys_tmpdir)) return sys_tmpdir; #endif sys_tmpdir = "/tmp"; - if (stat (sys_tmpdir, &sb) == 0) + if (file_iswdir (sys_tmpdir)) return sys_tmpdir; sys_tmpdir = "/var/tmp"; - if (stat (sys_tmpdir, &sb) == 0) + if (file_iswdir (sys_tmpdir)) return sys_tmpdir; sys_tmpdir = "/usr/tmp"; - if (stat (sys_tmpdir, &sb) == 0) + if (file_iswdir (sys_tmpdir)) return sys_tmpdir; sys_tmpdir = DEFAULT_TMPDIR; |