summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog11
-rw-r--r--MANIFEST2
-rw-r--r--ToDo5
-rw-r--r--configure4
-rw-r--r--configure.in4
-rw-r--r--dir.c167
-rw-r--r--missing/fnmatch.c199
-rw-r--r--missing/fnmatch.h57
-rw-r--r--ruby.c61
9 files changed, 228 insertions, 282 deletions
diff --git a/ChangeLog b/ChangeLog
index 43538e42a2..c551e1792a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+Thu Oct 21 16:14:19 1999 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * ruby.c (moreswitches): function to process string option;
+ the name is stolen from perl (not implementation).
+
+ * ruby.c (proc_options): use RUBYOPT environment variable to
+ retrieve the default options.
+
+ * dir.c (fnmatch): use eban's fnmatch; do not depend on systems's
+ fnmatch (which may have portability problem) anymore.
+
Wed Oct 20 15:14:24 1999 Yukihiro Matsumoto <matz@netlab.co.jp>
* marshal.c (marshal_load): should protect the generated object
diff --git a/MANIFEST b/MANIFEST
index 335b570bed..99c65e2edd 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -160,8 +160,6 @@ missing/dup2.c
missing/file.h
missing/finite.c
missing/flock.c
-missing/fnmatch.c
-missing/fnmatch.h
missing/isinf.c
missing/isnan.c
missing/memcmp.c
diff --git a/ToDo b/ToDo
index b3e3d80cab..793565a0e6 100644
--- a/ToDo
+++ b/ToDo
@@ -16,7 +16,8 @@ Language Spec.
Hacking Interpreter
-* RUBYOPT environment variable
+- use eban's fnmatch
+- RUBYOPT environment variable
* non-blocking open (e.g. for named pipe) for thread
* avoid blocking with gethostbyname/gethostbyaddr
* objectify interpreters
@@ -36,7 +37,7 @@ Standard Libraries
* Object#fmt(?)
* Time::strptime
* Integer[num], Float[num]; Fixnum[num]?
-* method to detect non-number trailer for to_i/to_f.
+* method to retrieve non-number trailer for to_i/to_f.
* Stream or Port, abstract superclass of IO ?
* String#{pred,prev}, String#downto
* optional stepsize argument for succ()
diff --git a/configure b/configure
index 462280501c..806621ee08 100644
--- a/configure
+++ b/configure
@@ -2199,7 +2199,7 @@ fi
for ac_hdr in stdlib.h string.h unistd.h limits.h sys/file.h sys/ioctl.h\
fcntl.h sys/fcntl.h sys/select.h sys/time.h sys/times.h sys/param.h\
- syscall.h pwd.h a.out.h utime.h memory.h direct.h fnmatch.h
+ syscall.h pwd.h a.out.h utime.h memory.h direct.h
do
ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
@@ -3041,7 +3041,7 @@ test $ac_cv_func_memcmp_clean = no && LIBOBJS="$LIBOBJS memcmp.${ac_objext}"
for ac_func in dup2 memmove mkdir strcasecmp strncasecmp strerror strftime\
strchr strstr strtoul strdup crypt flock vsnprintf\
- fnmatch isinf isnan finite
+ isinf isnan finite
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
echo "configure:3048: checking for $ac_func" >&5
diff --git a/configure.in b/configure.in
index 00b6ff12ce..a4b5264f87 100644
--- a/configure.in
+++ b/configure.in
@@ -156,7 +156,7 @@ AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS(stdlib.h string.h unistd.h limits.h sys/file.h sys/ioctl.h\
fcntl.h sys/fcntl.h sys/select.h sys/time.h sys/times.h sys/param.h\
- syscall.h pwd.h a.out.h utime.h memory.h direct.h fnmatch.h)
+ syscall.h pwd.h a.out.h utime.h memory.h direct.h)
dnl Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_UID_T
@@ -175,7 +175,7 @@ AC_FUNC_VFORK
AC_FUNC_MEMCMP
AC_REPLACE_FUNCS(dup2 memmove mkdir strcasecmp strncasecmp strerror strftime\
strchr strstr strtoul strdup crypt flock vsnprintf\
- fnmatch isinf isnan finite)
+ isinf isnan finite)
AC_CHECK_FUNCS(fmod killpg drand48 random wait4 waitpid syscall getcwd\
truncate chsize times utimes fcntl lockf setitimer\
setruid seteuid setreuid setrgid setegid setregid\
diff --git a/dir.c b/dir.c
index 642a960b54..e9ca286b91 100644
--- a/dir.c
+++ b/dir.c
@@ -47,12 +47,6 @@
# endif
#endif
-#ifdef HAVE_FNMATCH_H
-#include <fnmatch.h>
-#else
-#include "missing/fnmatch.h"
-#endif
-
#include <errno.h>
#ifdef USE_CWGUSI
# include <sys/errno.h>
@@ -66,6 +60,167 @@ char *getenv();
char *strchr _((char*,char));
#endif
+#include <ctype.h>
+
+#define FNM_NOESCAPE 0x01
+#define FNM_PATHNAME 0x02
+#define FNM_PERIOD 0x04
+#define FNM_NOCASE 0x08
+
+#define FNM_NOMATCH 1
+#define FNM_ERROR 2
+
+#define downcase(c) (nocase && isupper(c) ? tolower(c) : (c))
+
+#if defined DOSISH
+#define isdirsep(c) ((c) == '/' || (c) == '\\')
+static char *
+find_dirsep(s)
+ char *s;
+{
+ while (*s) {
+ if (isdirsep(*s))
+ return s;
+ s++;
+ }
+ return 0;
+}
+#else
+#define isdirsep(c) ((c) == '/')
+#define find_dirsep(s) strchr(s, '/')
+#endif
+
+static char *
+range(pat, test, flags)
+ char *pat;
+ char test;
+ int flags;
+{
+ int not, ok = 0;
+ int nocase = flags & FNM_NOCASE;
+ int escape = !(flags & FNM_NOESCAPE);
+
+ not = *pat == '!' || *pat == '^';
+ if (not)
+ pat++;
+
+ test = downcase(test);
+
+ while (*pat) {
+ int cstart, cend;
+ cstart = cend = *pat++;
+ if (cstart == ']')
+ return ok == not ? 0 : pat;
+ else if (escape && cstart == '\\')
+ cstart = cend = *pat++;
+ if (*pat == '-' && pat[1] != ']') {
+ if (escape && pat[1] == '\\')
+ pat++;
+ cend = pat[1];
+ if (!cend)
+ return 0;
+ pat += 2;
+ }
+ if (downcase(cstart) <= test && test <= downcase(cend))
+ ok = 1;
+ }
+ return 0;
+}
+
+#define PERIOD(s) (period && *(s) == '.' && \
+ ((s) == string || pathname && isdirsep(*(s))))
+static int
+fnmatch(pat, string, flags)
+ char *pat;
+ char *string;
+ int flags;
+{
+ int c;
+ int test;
+ char *s = string;
+ int escape = !(flags & FNM_NOESCAPE);
+ int pathname = flags & FNM_PATHNAME;
+ int period = flags & FNM_PERIOD;
+ int nocase = flags & FNM_NOCASE;
+
+ while (c = *pat++) {
+ switch (c) {
+ case '?':
+ if (!*s || pathname && isdirsep(*s) || PERIOD(s))
+ return FNM_NOMATCH;
+ s++;
+ break;
+ case '*':
+ while ((c = *pat++) == '*')
+ ;
+
+ if (PERIOD(s))
+ return FNM_NOMATCH;
+
+ if (!c) {
+ if (pathname && find_dirsep(s))
+ return FNM_NOMATCH;
+ else
+ return 0;
+ }
+ else if (pathname && isdirsep(c)) {
+ s = find_dirsep(s);
+ if (s)
+ break;
+ return FNM_NOMATCH;
+ }
+
+ test = escape && c == '\\' ? *pat : c;
+ test = downcase(test);
+ pat--;
+ while (*s) {
+ if ((c == '[' || downcase(*s) == test) &&
+ !fnmatch(pat, s, flags & ~FNM_PERIOD))
+ return 0;
+ else if (pathname && isdirsep(*s))
+ break;
+ s++;
+ }
+ return FNM_NOMATCH;
+
+ case '[':
+ if (!*s || pathname && isdirsep(*s) || PERIOD(s))
+ return FNM_NOMATCH;
+ pat = range(pat, *s, flags);
+ if (!pat)
+ return FNM_NOMATCH;
+ s++;
+ break;
+
+ case '\\':
+ if (escape
+#if defined DOSISH
+ && *pat && strchr("*?[\\", *pat)
+#endif
+ ) {
+ c = *pat;
+ if (!c)
+ c = '\\';
+ else
+ pat++;
+ }
+ /* FALLTHROUGH */
+
+ default:
+#if defined DOSISH
+ if (pathname && isdirsep(c) && isdirsep(*s))
+ ;
+ else
+#endif
+ if(downcase(c) != downcase(*s))
+ return FNM_NOMATCH;
+ s++;
+ break;
+ }
+ }
+ return !*s ? 0 : FNM_NOMATCH;
+}
+
VALUE rb_cDir;
static void
diff --git a/missing/fnmatch.c b/missing/fnmatch.c
deleted file mode 100644
index 4cf746118a..0000000000
--- a/missing/fnmatch.c
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * Copyright (c) 1989, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Guido van Rossum.
- *
- * 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fnmatch.c 8.2 (Berkeley) 4/16/94";
-#endif /* LIBC_SCCS and not lint */
-
-/*
- * Function fnmatch() as specified in POSIX 1003.2-1992, section B.6.
- * Compares a filename or pathname to a pattern.
- */
-
-#include "missing/fnmatch.h"
-#include <string.h>
-
-#define EOS '\0'
-
-static char *rangematch();
-
-int
-fnmatch(pattern, string, flags)
- char *pattern;
- char *string;
- int flags;
-{
- char *stringstart;
- char c, test;
-
- for (stringstart = string;;) {
- switch (c = *pattern++) {
- case EOS:
- return (*string == EOS ? 0 : FNM_NOMATCH);
- case '?':
- if (*string == EOS) {
- return (FNM_NOMATCH);
- }
- if (*string == '/' && (flags & FNM_PATHNAME)) {
- return (FNM_NOMATCH);
- }
- if (*string == '.' && (flags & FNM_PERIOD) &&
- (string == stringstart ||
- ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) {
- return (FNM_NOMATCH);
- }
- ++string;
- break;
- case '*':
- c = *pattern;
- /* Collapse multiple stars. */
- while (c == '*') {
- c = *++pattern;
- }
-
- if (*string == '.' && (flags & FNM_PERIOD) &&
- (string == stringstart ||
- ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) {
- return (FNM_NOMATCH);
- }
-
- /* Optimize for pattern with * at end or before /. */
- if (c == EOS) {
- if (flags & FNM_PATHNAME) {
- return (strchr(string, '/') == NULL ? 0 : FNM_NOMATCH);
- }
- else {
- return (0);
- }
- }
- else if (c == '/' && flags & FNM_PATHNAME) {
- if ((string = strchr(string, '/')) == NULL) {
- return (FNM_NOMATCH);
- }
- break;
- }
-
- /* General case, use recursion. */
- while ((test = *string) != EOS) {
- if (!fnmatch(pattern, string, flags & ~FNM_PERIOD)) {
- return (0);
- }
- if (test == '/' && flags & FNM_PATHNAME) {
- break;
- }
- ++string;
- }
- return (FNM_NOMATCH);
- case '[':
- if (*string == EOS) {
- return (FNM_NOMATCH);
- }
- if (*string == '/' && flags & FNM_PATHNAME) {
- return (FNM_NOMATCH);
- }
- if (*string == '.' && (flags & FNM_PERIOD) &&
- (string == stringstart ||
- ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) {
- return (FNM_NOMATCH);
- }
- if ((pattern = rangematch(pattern, *string, flags)) == NULL) {
- return (FNM_NOMATCH);
- }
- ++string;
- break;
- case '\\':
- if (!(flags & FNM_NOESCAPE)) {
- if ((c = *pattern++) == EOS) {
- c = '\\';
- --pattern;
- }
- }
- /* FALLTHROUGH */
- default:
- if (c != *string) {
- return (FNM_NOMATCH);
- }
- string++;
- break;
- }
- /* NOTREACHED */
- }
-}
-
-static char*
-rangematch(pattern, test, flags)
- char *pattern;
- int test, flags;
-{
- int negate, ok;
- char c, c2;
-
- /*
- * A bracket expression starting with an unquoted circumflex
- * character produces unspecified results (IEEE 1003.2-1992,
- * 3.13.2). This implementation treats it like '!', for
- * consistency with the regular expression syntax.
- * J.T. Conklin (conklin@ngai.kaleida.com)
- */
- if ((negate = (*pattern == '!' || *pattern == '^'))) {
- ++pattern;
- }
-
- for (ok = 0; (c = *pattern++) != ']';) {
- if (c == '\\' && !(flags & FNM_NOESCAPE)) {
- c = *pattern++;
- }
- if (c == EOS) {
- return (NULL);
- }
- if (*pattern == '-' && (c2 = *(pattern + 1)) != EOS && c2 != ']') {
- pattern += 2;
- if (c2 == '\\' && !(flags & FNM_NOESCAPE)) {
- c2 = *pattern++;
- }
- if (c2 == EOS) {
- return (NULL);
- }
- if (c <= test && test <= c2) {
- ok = 1;
- }
- }
- else if (c == test) {
- ok = 1;
- }
- }
- return (ok == negate ? NULL : pattern);
-}
diff --git a/missing/fnmatch.h b/missing/fnmatch.h
deleted file mode 100644
index 773851625a..0000000000
--- a/missing/fnmatch.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*-
- * Copyright (c) 1992, 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.
- *
- * @(#)fnmatch.h 8.1 (Berkeley) 6/2/93
- */
-
-/* This file has been modified by matz@netlab.co.jp */
-
-#ifndef _FNMATCH_H_
-#define _FNMATCH_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define FNM_NOMATCH 1 /* Match failed. */
-
-#define FNM_NOESCAPE 0x01 /* Disable backslash escaping. */
-#define FNM_PATHNAME 0x02 /* Slash must be matched by slash. */
-#define FNM_PERIOD 0x04 /* Period must be matched by period. */
-
-int fnmatch();
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* !_FNMATCH_H_ */
diff --git a/ruby.c b/ruby.c
index 12aa708fb0..0fa3cb5282 100644
--- a/ruby.c
+++ b/ruby.c
@@ -292,6 +292,26 @@ process_sflag()
}
}
+static void proc_options _((int argc, char **argv));
+
+static char*
+moreswitches(s)
+ char *s;
+{
+ int argc; char *argv[3]; char **argvp = argv;
+ char *p = s;
+
+ argc = 2; argv[0] = argv[2] = 0;
+ while (*s && !ISSPACE(*s))
+ s++;
+ argv[1] = ALLOCA_N(char, s - p + 2);
+ sprintf(argv[1], "-%s", p);
+ proc_options(argc, argv);
+ while (*s && ISSPACE(*s))
+ s++;
+ return s;
+}
+
static void
proc_options(argc, argv)
int argc;
@@ -528,6 +548,34 @@ proc_options(argc, argv)
switch_end:
if (argv0 == 0) return;
+ if (rb_safe_level() == 0 && (s = getenv("RUBYOPT"))) {
+ while (ISSPACE(*s)) s++;
+ if (*s == '-' && *(s+1) == 'T') {
+ int numlen;
+ int v = 1;
+
+ s += 2;
+ if (*++s) {
+ v = scan_oct(s, 2, &numlen);
+ if (numlen == 0) v = 1;
+ }
+ rb_set_safe_level(v);
+ }
+ else {
+ while (s && *s) {
+ while (ISSPACE(*s)) s++;
+ if (*s == '-') {
+ s++;
+ if (ISSPACE(*s)) continue;
+ }
+ if (!*s) break;
+ if (!strchr("IdvwrK", *s))
+ rb_raise(rb_eRuntimeError, "Illegal switch in RUBYOPT: -%c", *s);
+ s = moreswitches(s);
+ }
+ }
+ }
+
if (e_script) {
argc++, argv--;
argv[0] = script;
@@ -681,19 +729,8 @@ load_file(fname, script)
if (RSTRING(line)->ptr[RSTRING(line)->len-2] == '\r')
RSTRING(line)->ptr[RSTRING(line)->len-2] = '\0';
if (p = strstr(p, " -")) {
- int argc; char *argv[3]; char **argvp = argv;
- char *s = ++p;
-
- argc = 2; argv[0] = argv[2] = 0;
while (*p == '-') {
- while (*s && !ISSPACE(*s))
- s++;
- *s = '\0';
- argv[1] = p;
- proc_options(argc, argv);
- p = ++s;
- while (*p && ISSPACE(*p))
- p++;
+ p = moreswitches(p+1);
}
}
}