Permalink
Browse files

RUBYOPT

git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@551 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
matz committed Oct 21, 1999
1 parent f107252 commit c651f107a513d6e910ad0b3dfe7cacaa50dad3ba
Showing with 228 additions and 282 deletions.
  1. +11 −0 ChangeLog
  2. +0 −2 MANIFEST
  3. +3 −2 ToDo
  4. +2 −2 configure
  5. +2 −2 configure.in
  6. +161 −6 dir.c
  7. +0 −199 missing/fnmatch.c
  8. +0 −57 missing/fnmatch.h
  9. +49 −12 ruby.c
View
@@ -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
View
@@ -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
View
5 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()
View
@@ -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
View
@@ -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\
View
167 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
Oops, something went wrong.

0 comments on commit c651f10

Please sign in to comment.