git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@563 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 1999-11-11 04:08:26 +00:00
parent 1f13348b22
commit 943e99e627
5 changed files with 56 additions and 22 deletions

View File

@ -1,3 +1,12 @@
Wed Nov 10 21:54:11 1999 EGUCHI Osamu <eguchi@shizuokanet.ne.jp>
* hash.c (rb_any_cmp): Fixed return without value.
Wed Nov 10 17:57:06 1999 Yukihiro Matsumoto <matz@netlab.co.jp>
* sprintf.c: incorporate <yasuf@big.or.jp>'s sprintf patch at
[ruby-dev:7754].
Wed Nov 10 08:28:53 1999 Yukihiro Matsumoto <matz@netlab.co.jp> Wed Nov 10 08:28:53 1999 Yukihiro Matsumoto <matz@netlab.co.jp>
* eval.c (rb_call0): supply class parameter for each invocation. * eval.c (rb_call0): supply class parameter for each invocation.

1
ToDo
View File

@ -35,6 +35,7 @@ Standard Libraries
- hash.fetch(key) raises exception if key is not found. - hash.fetch(key) raises exception if key is not found.
- Array#{first,last,at} - Array#{first,last,at}
- Dir.glob(pat){|f|...} - Dir.glob(pat){|f|...}
- sprintf/printf's $ to specify argument order
* Dir.glob("**/*.c") ala zsh * Dir.glob("**/*.c") ala zsh
* Struct::new([name,]member,...) ?? * Struct::new([name,]member,...) ??
* String#scanf(?) * String#scanf(?)

10
hash.c
View File

@ -79,19 +79,17 @@ static int
rb_any_cmp(a, b) rb_any_cmp(a, b)
VALUE a, b; VALUE a, b;
{ {
VALUE args[2];
if (FIXNUM_P(a)) { if (FIXNUM_P(a)) {
if (FIXNUM_P(b)) return a != b; if (FIXNUM_P(b)) return a != b;
} }
else if (TYPE(a) == T_STRING) { else if (TYPE(a) == T_STRING) {
if (TYPE(b) == T_STRING) return rb_str_cmp(a, b); if (TYPE(b) == T_STRING) return rb_str_cmp(a, b);
} }
else {
VALUE args[2];
args[0] = a; args[0] = a;
args[1] = b; args[1] = b;
return !rb_with_disable_interrupt(eql, (VALUE)args); return !rb_with_disable_interrupt(eql, (VALUE)args);
}
} }
static int static int

View File

@ -48,13 +48,6 @@
# include <sys/types.h> # include <sys/types.h>
#endif #endif
#if defined(STDC_HEADERS)
# include <stddef.h>
#else
/* We need this for `regex.h', and perhaps for the Emacs include files. */
# include <sys/types.h>
#endif
#ifndef __STDC__ #ifndef __STDC__
# define volatile # define volatile
#endif #endif

View File

@ -136,7 +136,29 @@ double rb_big2dbl _((VALUE));
} }
#define GETARG() \ #define GETARG() \
((argc == 0)?(rb_raise(rb_eArgError, "too few argument."),0):(argc--,((argv++)[0]))) ((nextarg >= argc) ? (rb_raise(rb_eArgError, "too few argument."), 0) : argv[nextarg++])
#define GETASTER(val) { \
t = p++; \
n = 0; \
for (; p < end && ISDIGIT(*p); p++) { \
n = 10 * n + (*p - '0'); \
} \
if (p >= end) { \
rb_raise(rb_eArgError, "malformed format string - %%*[0-9]"); \
} \
if (*p == '$') { \
int curarg = nextarg; \
nextarg = n; \
tmp = GETARG(); \
nextarg = curarg; \
} \
else { \
tmp = GETARG(); \
p = t; \
} \
val = NUM2INT(tmp); \
}
VALUE VALUE
rb_f_sprintf(argc, argv) rb_f_sprintf(argc, argv)
@ -149,6 +171,7 @@ rb_f_sprintf(argc, argv)
VALUE result; VALUE result;
int width, prec, flags = FNONE; int width, prec, flags = FNONE;
int nextarg = 0;
VALUE tmp; VALUE tmp;
VALUE str; VALUE str;
@ -161,6 +184,7 @@ rb_f_sprintf(argc, argv)
for (; p < end; p++) { for (; p < end; p++) {
char *t; char *t;
int n;
for (t = p; t < end && *t != '%'; t++) ; for (t = p; t < end && *t != '%'; t++) ;
CHECK(t - p); CHECK(t - p);
@ -208,14 +232,20 @@ rb_f_sprintf(argc, argv)
case '1': case '2': case '3': case '4': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9': case '5': case '6': case '7': case '8': case '9':
flags |= FWIDTH; n = 0;
width = 0;
for (; p < end && ISDIGIT(*p); p++) { for (; p < end && ISDIGIT(*p); p++) {
width = 10 * width + (*p - '0'); n = 10 * n + (*p - '0');
} }
if (p >= end) { if (p >= end) {
rb_raise(rb_eArgError, "malformed format string - %%[0-9]"); rb_raise(rb_eArgError, "malformed format string - %%[0-9]");
} }
if (*p == '$') {
nextarg = n;
p++;
goto retry;
}
width = n;
flags |= FWIDTH;
goto retry; goto retry;
case '*': case '*':
@ -224,8 +254,7 @@ rb_f_sprintf(argc, argv)
} }
flags |= FWIDTH; flags |= FWIDTH;
tmp = GETARG(); GETASTER(width);
width = NUM2INT(tmp);
if (width < 0) { if (width < 0) {
flags |= FMINUS; flags |= FMINUS;
width = -width; width = -width;
@ -241,8 +270,7 @@ rb_f_sprintf(argc, argv)
prec = 0; prec = 0;
p++; p++;
if (*p == '*') { if (*p == '*') {
tmp = GETARG(); GETASTER(prec);
prec = NUM2INT(tmp);
if (prec > 0) if (prec > 0)
flags |= FPREC; flags |= FPREC;
p++; p++;
@ -612,9 +640,14 @@ rb_f_sprintf(argc, argv)
} }
sprint_exit: sprint_exit:
if (RTEST(ruby_verbose) && argc > 0) { #if 0
/* XXX - We cannot validiate the number of arguments because
* the format string may contain `n$'-style argument selector.
*/
if (RTEST(ruby_verbose) && nextarg < argc) {
rb_raise(rb_eArgError, "too many argument for format string"); rb_raise(rb_eArgError, "too many argument for format string");
} }
#endif
result = rb_str_new(buf, blen); result = rb_str_new(buf, blen);
free(buf); free(buf);