2000-05-09 08:53:16 +04:00
|
|
|
/**********************************************************************
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
sprintf.c -
|
|
|
|
|
|
|
|
$Author$
|
|
|
|
$Date$
|
|
|
|
created at: Fri Oct 15 10:39:26 JST 1993
|
|
|
|
|
2003-01-16 10:34:03 +03:00
|
|
|
Copyright (C) 1993-2003 Yukihiro Matsumoto
|
2000-05-01 13:42:38 +04:00
|
|
|
Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
|
2000-05-09 08:53:16 +04:00
|
|
|
Copyright (C) 2000 Information-technology Promotion Agency, Japan
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-05-09 08:53:16 +04:00
|
|
|
**********************************************************************/
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2007-06-10 07:06:15 +04:00
|
|
|
#include "ruby/ruby.h"
|
|
|
|
#include "ruby/re.h"
|
1998-01-16 15:13:05 +03:00
|
|
|
#include <ctype.h>
|
1999-08-13 09:45:20 +04:00
|
|
|
#include <math.h>
|
2005-07-23 05:02:18 +04:00
|
|
|
#include <stdarg.h>
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
#define BIT_DIGITS(N) (((N)*146)/485 + 1) /* log2(10) =~ 146/485 */
|
|
|
|
|
* bignum.c: changed `foo _((boo))' to `foo(boo)`. [ruby-dev:27056]
* defines.h, dir.c, dln.h, enumerator.c, env.h, error.c, eval.c, file.c,
gc.c, hash.c, inits.c, intern.h, io.c, lex.c, marshal.c, missing.h,
node.h, numeric.c, pack.c, process.c, re.h, ruby.c, ruby.h, rubyio.h,
rubysig.h, signal.c, sprintf.c, st.h, string.c, struct.c, time.c,
util.c, util.h, variable.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-14 10:32:32 +04:00
|
|
|
static void fmt_setup(char*,int,int,int,int);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
static char*
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
remove_sign_bits(char *str, int base)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2004-07-18 03:14:52 +04:00
|
|
|
char *s, *t;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
s = t = str;
|
|
|
|
|
|
|
|
if (base == 16) {
|
2004-07-18 03:14:52 +04:00
|
|
|
while (*t == 'f') {
|
2002-04-10 12:45:26 +04:00
|
|
|
t++;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (base == 8) {
|
2003-03-20 09:27:22 +03:00
|
|
|
if (*t == '3') t++;
|
2004-07-18 03:14:52 +04:00
|
|
|
while (*t == '7') {
|
2002-04-10 12:45:26 +04:00
|
|
|
t++;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (base == 2) {
|
2004-07-18 03:14:52 +04:00
|
|
|
while (*t == '1') {
|
2002-04-10 12:45:26 +04:00
|
|
|
t++;
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2004-07-18 03:14:52 +04:00
|
|
|
if (t > s) {
|
|
|
|
while (*t) *s++ = *t++;
|
|
|
|
*s = '\0';
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2003-03-20 09:27:22 +03:00
|
|
|
static char
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
sign_bits(int base, const char *p)
|
2003-03-20 09:27:22 +03:00
|
|
|
{
|
|
|
|
char c = '.';
|
|
|
|
|
|
|
|
switch (base) {
|
|
|
|
case 16:
|
|
|
|
if (*p == 'X') c = 'F';
|
|
|
|
else c = 'f';
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
c = '7'; break;
|
|
|
|
case 2:
|
|
|
|
c = '1'; break;
|
|
|
|
}
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
#define FNONE 0
|
|
|
|
#define FSHARP 1
|
|
|
|
#define FMINUS 2
|
|
|
|
#define FPLUS 4
|
|
|
|
#define FZERO 8
|
1999-01-20 07:59:39 +03:00
|
|
|
#define FSPACE 16
|
|
|
|
#define FWIDTH 32
|
|
|
|
#define FPREC 64
|
2007-07-16 00:45:55 +04:00
|
|
|
#define FPREC0 128
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-16 17:44:19 +04:00
|
|
|
#define CHECK(l) do {\
|
1998-01-16 15:13:05 +03:00
|
|
|
while (blen + (l) >= bsiz) {\
|
|
|
|
bsiz*=2;\
|
2002-10-16 17:44:19 +04:00
|
|
|
}\
|
|
|
|
rb_str_resize(result, bsiz);\
|
2006-08-31 14:47:44 +04:00
|
|
|
buf = RSTRING_PTR(result);\
|
2002-10-16 17:44:19 +04:00
|
|
|
} while (0)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-04-18 12:46:18 +04:00
|
|
|
#define PUSH(s, l) do { \
|
1998-01-16 15:13:05 +03:00
|
|
|
CHECK(l);\
|
|
|
|
memcpy(&buf[blen], s, l);\
|
|
|
|
blen += (l);\
|
2002-04-18 12:46:18 +04:00
|
|
|
} while (0)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2005-07-23 05:02:18 +04:00
|
|
|
#define FILL(c, l) do { \
|
|
|
|
CHECK(l);\
|
|
|
|
memset(&buf[blen], c, l);\
|
|
|
|
blen += (l);\
|
|
|
|
} while (0)
|
|
|
|
|
2002-10-16 17:44:19 +04:00
|
|
|
#define GETARG() (nextvalue != Qundef ? nextvalue : \
|
|
|
|
posarg < 0 ? \
|
|
|
|
(rb_raise(rb_eArgError, "unnumbered(%d) mixed with numbered", nextarg), 0) : \
|
|
|
|
(posarg = nextarg++, GETNTHARG(posarg)))
|
|
|
|
|
|
|
|
#define GETPOSARG(n) (posarg > 0 ? \
|
|
|
|
(rb_raise(rb_eArgError, "numbered(%d) after unnumbered(%d)", n, posarg), 0) : \
|
|
|
|
((n < 1) ? (rb_raise(rb_eArgError, "invalid index - %d$", n), 0) : \
|
|
|
|
(posarg = -1, GETNTHARG(n))))
|
|
|
|
|
|
|
|
#define GETNTHARG(nth) \
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
((nth >= argc) ? (rb_raise(rb_eArgError, "too few arguments"), 0) : argv[nth])
|
1999-11-11 07:08:26 +03:00
|
|
|
|
2007-07-16 00:45:55 +04:00
|
|
|
#define GETNUM(n, val) \
|
1999-11-11 07:08:26 +03:00
|
|
|
for (; p < end && ISDIGIT(*p); p++) { \
|
2005-12-07 11:41:59 +03:00
|
|
|
int next_n = 10 * n + (*p - '0'); \
|
|
|
|
if (next_n / 10 != n) {\
|
2005-12-07 09:36:38 +03:00
|
|
|
rb_raise(rb_eArgError, #val " too big"); \
|
|
|
|
} \
|
2005-12-07 11:41:59 +03:00
|
|
|
n = next_n; \
|
1999-11-11 07:08:26 +03:00
|
|
|
} \
|
|
|
|
if (p >= end) { \
|
|
|
|
rb_raise(rb_eArgError, "malformed format string - %%*[0-9]"); \
|
2007-07-16 00:45:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#define GETASTER(val) do { \
|
|
|
|
t = p++; \
|
|
|
|
n = 0; \
|
|
|
|
GETNUM(n, val); \
|
1999-11-11 07:08:26 +03:00
|
|
|
if (*p == '$') { \
|
2002-10-16 17:44:19 +04:00
|
|
|
tmp = GETPOSARG(n); \
|
1999-11-11 07:08:26 +03:00
|
|
|
} \
|
|
|
|
else { \
|
|
|
|
tmp = GETARG(); \
|
|
|
|
p = t; \
|
|
|
|
} \
|
|
|
|
val = NUM2INT(tmp); \
|
2002-04-18 12:46:18 +04:00
|
|
|
} while (0)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* format(format_string [, arguments...] ) => string
|
|
|
|
* sprintf(format_string [, arguments...] ) => string
|
|
|
|
*
|
|
|
|
* Returns the string resulting from applying <i>format_string</i> to
|
|
|
|
* any additional arguments. Within the format string, any characters
|
|
|
|
* other than format sequences are copied to the result. A format
|
|
|
|
* sequence consists of a percent sign, followed by optional flags,
|
|
|
|
* width, and precision indicators, then terminated with a field type
|
|
|
|
* character. The field type controls how the corresponding
|
|
|
|
* <code>sprintf</code> argument is to be interpreted, while the flags
|
|
|
|
* modify that interpretation. The field type characters are listed
|
|
|
|
* in the table at the end of this section. The flag characters are:
|
|
|
|
*
|
|
|
|
* Flag | Applies to | Meaning
|
|
|
|
* ---------+--------------+-----------------------------------------
|
2005-09-16 07:09:51 +04:00
|
|
|
* space | bdeEfgGiouxX | Leave a space at the start of
|
2003-12-28 09:33:07 +03:00
|
|
|
* | | positive numbers.
|
|
|
|
* ---------+--------------+-----------------------------------------
|
|
|
|
* (digit)$ | all | Specifies the absolute argument number
|
|
|
|
* | | for this field. Absolute and relative
|
|
|
|
* | | argument numbers cannot be mixed in a
|
|
|
|
* | | sprintf string.
|
|
|
|
* ---------+--------------+-----------------------------------------
|
|
|
|
* # | beEfgGoxX | Use an alternative format. For the
|
|
|
|
* | | conversions `o', `x', `X', and `b',
|
|
|
|
* | | prefix the result with ``0'', ``0x'', ``0X'',
|
|
|
|
* | | and ``0b'', respectively. For `e',
|
|
|
|
* | | `E', `f', `g', and 'G', force a decimal
|
|
|
|
* | | point to be added, even if no digits follow.
|
|
|
|
* | | For `g' and 'G', do not remove trailing zeros.
|
|
|
|
* ---------+--------------+-----------------------------------------
|
2005-09-16 07:09:51 +04:00
|
|
|
* + | bdeEfgGiouxX | Add a leading plus sign to positive numbers.
|
2003-12-28 09:33:07 +03:00
|
|
|
* ---------+--------------+-----------------------------------------
|
|
|
|
* - | all | Left-justify the result of this conversion.
|
|
|
|
* ---------+--------------+-----------------------------------------
|
2005-09-16 07:09:51 +04:00
|
|
|
* 0 (zero) | bdeEfgGiouxX | Pad with zeros, not spaces.
|
2003-12-28 09:33:07 +03:00
|
|
|
* ---------+--------------+-----------------------------------------
|
|
|
|
* * | all | Use the next argument as the field width.
|
|
|
|
* | | If negative, left-justify the result. If the
|
|
|
|
* | | asterisk is followed by a number and a dollar
|
|
|
|
* | | sign, use the indicated argument as the width.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* The field width is an optional integer, followed optionally by a
|
|
|
|
* period and a precision. The width specifies the minimum number of
|
|
|
|
* characters that will be written to the result for this field. For
|
|
|
|
* numeric fields, the precision controls the number of decimal places
|
|
|
|
* displayed. For string fields, the precision determines the maximum
|
|
|
|
* number of characters to be copied from the string. (Thus, the format
|
|
|
|
* sequence <code>%10.10s</code> will always contribute exactly ten
|
|
|
|
* characters to the result.)
|
|
|
|
*
|
|
|
|
* The field types are:
|
|
|
|
*
|
|
|
|
* Field | Conversion
|
|
|
|
* ------+--------------------------------------------------------------
|
|
|
|
* b | Convert argument as a binary number.
|
|
|
|
* c | Argument is the numeric code for a single character.
|
|
|
|
* d | Convert argument as a decimal number.
|
|
|
|
* E | Equivalent to `e', but uses an uppercase E to indicate
|
|
|
|
* | the exponent.
|
|
|
|
* e | Convert floating point argument into exponential notation
|
|
|
|
* | with one digit before the decimal point. The precision
|
|
|
|
* | determines the number of fractional digits (defaulting to six).
|
|
|
|
* f | Convert floating point argument as [-]ddd.ddd,
|
|
|
|
* | where the precision determines the number of digits after
|
|
|
|
* | the decimal point.
|
|
|
|
* G | Equivalent to `g', but use an uppercase `E' in exponent form.
|
|
|
|
* g | Convert a floating point number using exponential form
|
|
|
|
* | if the exponent is less than -4 or greater than or
|
|
|
|
* | equal to the precision, or in d.dddd form otherwise.
|
|
|
|
* i | Identical to `d'.
|
|
|
|
* o | Convert argument as an octal number.
|
|
|
|
* p | The valuing of argument.inspect.
|
|
|
|
* s | Argument is a string to be substituted. If the format
|
|
|
|
* | sequence contains a precision, at most that many characters
|
|
|
|
* | will be copied.
|
2006-07-28 05:23:55 +04:00
|
|
|
* u | Treat argument as an unsigned decimal number. Negative integers
|
|
|
|
* | are displayed as a 32 bit two's complement plus one for the
|
|
|
|
* | underlying architecture; that is, 2 ** 32 + n. However, since
|
|
|
|
* | Ruby has no inherent limit on bits used to represent the
|
|
|
|
* | integer, this value is preceded by two dots (..) in order to
|
|
|
|
* | indicate a infinite number of leading sign bits.
|
2003-12-28 09:33:07 +03:00
|
|
|
* X | Convert argument as a hexadecimal number using uppercase
|
|
|
|
* | letters. Negative numbers will be displayed with two
|
|
|
|
* | leading periods (representing an infinite string of
|
|
|
|
* | leading 'FF's.
|
|
|
|
* x | Convert argument as a hexadecimal number.
|
|
|
|
* | Negative numbers will be displayed with two
|
|
|
|
* | leading periods (representing an infinite string of
|
|
|
|
* | leading 'ff's.
|
|
|
|
*
|
|
|
|
* Examples:
|
|
|
|
*
|
|
|
|
* sprintf("%d %04x", 123, 123) #=> "123 007b"
|
|
|
|
* sprintf("%08b '%4s'", 123, 123) #=> "01111011 ' 123'"
|
|
|
|
* sprintf("%1$*2$s %2$d %1$s", "hello", 8) #=> " hello 8 hello"
|
|
|
|
* sprintf("%1$*2$s %2$d", "hello", -8) #=> "hello -8"
|
|
|
|
* sprintf("%+g:% g:%-g", 1.23, 1.23, 1.23) #=> "+1.23: 1.23:1.23"
|
2006-07-28 05:23:55 +04:00
|
|
|
* sprintf("%u", -123) #=> "..4294967173"
|
2003-12-28 09:33:07 +03:00
|
|
|
*/
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_f_sprintf(int argc, const VALUE *argv)
|
1999-01-20 07:59:39 +03:00
|
|
|
{
|
2005-07-23 05:02:18 +04:00
|
|
|
return rb_str_format(argc - 1, argv + 1, GETNTHARG(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_str_format(int argc, const VALUE *argv, VALUE fmt)
|
2005-07-23 05:02:18 +04:00
|
|
|
{
|
2004-07-18 03:14:52 +04:00
|
|
|
const char *p, *end;
|
|
|
|
char *buf;
|
1999-01-20 07:59:39 +03:00
|
|
|
int blen, bsiz;
|
|
|
|
VALUE result;
|
|
|
|
|
|
|
|
int width, prec, flags = FNONE;
|
2002-10-16 17:44:19 +04:00
|
|
|
int nextarg = 1;
|
|
|
|
int posarg = 0;
|
1999-12-06 12:04:03 +03:00
|
|
|
int tainted = 0;
|
2002-10-16 17:44:19 +04:00
|
|
|
VALUE nextvalue;
|
1999-01-20 07:59:39 +03:00
|
|
|
VALUE tmp;
|
|
|
|
VALUE str;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2007-07-16 00:45:55 +04:00
|
|
|
#define CHECK_FOR_WIDTH(f) \
|
|
|
|
if ((f) & FWIDTH) { \
|
|
|
|
rb_raise(rb_eArgError, "width given twice"); \
|
|
|
|
} \
|
|
|
|
if ((f) & FPREC0) { \
|
|
|
|
rb_raise(rb_eArgError, "width after precision"); \
|
|
|
|
}
|
|
|
|
#define CHECK_FOR_FLAGS(f) \
|
|
|
|
if ((f) & FWIDTH) { \
|
|
|
|
rb_raise(rb_eArgError, "flag after width"); \
|
|
|
|
} \
|
|
|
|
if ((f) & FPREC0) { \
|
|
|
|
rb_raise(rb_eArgError, "flag after precision"); \
|
|
|
|
}
|
|
|
|
|
2005-07-23 05:02:18 +04:00
|
|
|
++argc;
|
|
|
|
--argv;
|
1999-12-06 12:04:03 +03:00
|
|
|
if (OBJ_TAINTED(fmt)) tainted = 1;
|
2001-05-02 08:22:21 +04:00
|
|
|
StringValue(fmt);
|
2004-12-08 08:32:26 +03:00
|
|
|
fmt = rb_str_new4(fmt);
|
2006-08-31 14:47:44 +04:00
|
|
|
p = RSTRING_PTR(fmt);
|
|
|
|
end = p + RSTRING_LEN(fmt);
|
1998-01-16 15:13:05 +03:00
|
|
|
blen = 0;
|
|
|
|
bsiz = 120;
|
2002-10-16 17:44:19 +04:00
|
|
|
result = rb_str_buf_new(bsiz);
|
2006-08-31 14:47:44 +04:00
|
|
|
buf = RSTRING_PTR(result);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
for (; p < end; p++) {
|
2004-07-18 03:14:52 +04:00
|
|
|
const char *t;
|
1999-11-11 07:08:26 +03:00
|
|
|
int n;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
for (t = p; t < end && *t != '%'; t++) ;
|
|
|
|
PUSH(p, t - p);
|
|
|
|
if (t >= end) {
|
|
|
|
/* end of fmt string */
|
|
|
|
goto sprint_exit;
|
|
|
|
}
|
|
|
|
p = t + 1; /* skip `%' */
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
width = prec = -1;
|
2002-10-16 17:44:19 +04:00
|
|
|
nextvalue = Qundef;
|
1998-01-16 15:13:05 +03:00
|
|
|
retry:
|
|
|
|
switch (*p) {
|
|
|
|
default:
|
1999-01-20 07:59:39 +03:00
|
|
|
if (ISPRINT(*p))
|
|
|
|
rb_raise(rb_eArgError, "malformed format string - %%%c", *p);
|
1998-01-16 15:13:05 +03:00
|
|
|
else
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_raise(rb_eArgError, "malformed format string");
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ' ':
|
2007-07-16 00:45:55 +04:00
|
|
|
CHECK_FOR_FLAGS(flags);
|
1999-01-20 07:59:39 +03:00
|
|
|
flags |= FSPACE;
|
1998-01-16 15:13:05 +03:00
|
|
|
p++;
|
|
|
|
goto retry;
|
|
|
|
|
|
|
|
case '#':
|
2007-07-16 00:45:55 +04:00
|
|
|
CHECK_FOR_FLAGS(flags);
|
1998-01-16 15:13:05 +03:00
|
|
|
flags |= FSHARP;
|
|
|
|
p++;
|
|
|
|
goto retry;
|
|
|
|
|
|
|
|
case '+':
|
2007-07-16 00:45:55 +04:00
|
|
|
CHECK_FOR_FLAGS(flags);
|
1998-01-16 15:13:05 +03:00
|
|
|
flags |= FPLUS;
|
|
|
|
p++;
|
|
|
|
goto retry;
|
|
|
|
|
|
|
|
case '-':
|
2007-07-16 00:45:55 +04:00
|
|
|
CHECK_FOR_FLAGS(flags);
|
1998-01-16 15:13:05 +03:00
|
|
|
flags |= FMINUS;
|
|
|
|
p++;
|
|
|
|
goto retry;
|
|
|
|
|
|
|
|
case '0':
|
2007-07-16 00:45:55 +04:00
|
|
|
CHECK_FOR_FLAGS(flags);
|
1998-01-16 15:13:05 +03:00
|
|
|
flags |= FZERO;
|
|
|
|
p++;
|
|
|
|
goto retry;
|
|
|
|
|
|
|
|
case '1': case '2': case '3': case '4':
|
|
|
|
case '5': case '6': case '7': case '8': case '9':
|
1999-11-11 07:08:26 +03:00
|
|
|
n = 0;
|
2007-07-16 00:45:55 +04:00
|
|
|
GETNUM(n, width);
|
1999-11-11 07:08:26 +03:00
|
|
|
if (*p == '$') {
|
2002-10-16 17:44:19 +04:00
|
|
|
if (nextvalue != Qundef) {
|
|
|
|
rb_raise(rb_eArgError, "value given twice - %d$", n);
|
|
|
|
}
|
|
|
|
nextvalue = GETPOSARG(n);
|
1999-11-11 07:08:26 +03:00
|
|
|
p++;
|
|
|
|
goto retry;
|
|
|
|
}
|
2007-08-02 08:46:41 +04:00
|
|
|
CHECK_FOR_WIDTH(flags);
|
1999-11-11 07:08:26 +03:00
|
|
|
width = n;
|
|
|
|
flags |= FWIDTH;
|
1998-01-16 15:13:05 +03:00
|
|
|
goto retry;
|
|
|
|
|
|
|
|
case '*':
|
2007-07-16 00:45:55 +04:00
|
|
|
CHECK_FOR_WIDTH(flags);
|
1998-01-16 15:13:05 +03:00
|
|
|
flags |= FWIDTH;
|
1999-11-11 07:08:26 +03:00
|
|
|
GETASTER(width);
|
1998-01-16 15:13:05 +03:00
|
|
|
if (width < 0) {
|
|
|
|
flags |= FMINUS;
|
1999-01-20 07:59:39 +03:00
|
|
|
width = -width;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
p++;
|
|
|
|
goto retry;
|
|
|
|
|
|
|
|
case '.':
|
2007-07-16 00:45:55 +04:00
|
|
|
if (flags & FPREC0) {
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_raise(rb_eArgError, "precision given twice");
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2007-07-16 00:45:55 +04:00
|
|
|
flags |= FPREC|FPREC0;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
prec = 0;
|
|
|
|
p++;
|
|
|
|
if (*p == '*') {
|
1999-11-11 07:08:26 +03:00
|
|
|
GETASTER(prec);
|
2000-06-19 12:38:11 +04:00
|
|
|
if (prec < 0) { /* ignore negative precision */
|
|
|
|
flags &= ~FPREC;
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
p++;
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
|
2007-07-16 00:45:55 +04:00
|
|
|
GETNUM(prec, precision);
|
1998-01-16 15:13:05 +03:00
|
|
|
goto retry;
|
|
|
|
|
|
|
|
case '\n':
|
|
|
|
case '\0':
|
2007-07-16 00:45:55 +04:00
|
|
|
p--;
|
1998-01-16 15:13:05 +03:00
|
|
|
case '%':
|
1999-09-01 13:48:03 +04:00
|
|
|
if (flags != FNONE) {
|
|
|
|
rb_raise(rb_eArgError, "illegal format character - %%");
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
PUSH("%", 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'c':
|
|
|
|
{
|
|
|
|
VALUE val = GETARG();
|
2006-08-04 15:46:44 +04:00
|
|
|
VALUE tmp;
|
1998-01-16 15:13:05 +03:00
|
|
|
char c;
|
|
|
|
|
2006-08-04 15:46:44 +04:00
|
|
|
tmp = rb_check_string_type(val);
|
|
|
|
if (!NIL_P(tmp)) {
|
2006-08-31 14:47:44 +04:00
|
|
|
if (RSTRING_LEN(tmp) != 1) {
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-10 01:20:17 +04:00
|
|
|
rb_raise(rb_eArgError, "%%c requires a character");
|
|
|
|
}
|
2006-08-31 14:47:44 +04:00
|
|
|
c = RSTRING_PTR(tmp)[0];
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-10 01:20:17 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
c = NUM2INT(val) & 0xff;
|
|
|
|
}
|
2005-07-23 05:02:18 +04:00
|
|
|
if (!(flags & FWIDTH)) {
|
|
|
|
PUSH(&c, 1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
FILL(' ', width);
|
|
|
|
buf[blen - ((flags & FMINUS) ? width : 1)] = c;
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 's':
|
2003-07-03 15:02:53 +04:00
|
|
|
case 'p':
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
VALUE arg = GETARG();
|
2002-08-21 19:47:54 +04:00
|
|
|
long len;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2003-07-03 15:02:53 +04:00
|
|
|
if (*p == 'p') arg = rb_inspect(arg);
|
1999-01-20 07:59:39 +03:00
|
|
|
str = rb_obj_as_string(arg);
|
1999-12-06 12:04:03 +03:00
|
|
|
if (OBJ_TAINTED(str)) tainted = 1;
|
2006-08-31 14:47:44 +04:00
|
|
|
len = RSTRING_LEN(str);
|
1998-01-16 15:13:05 +03:00
|
|
|
if (flags&FPREC) {
|
|
|
|
if (prec < len) {
|
2000-12-12 10:42:35 +03:00
|
|
|
len = prec;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
2006-06-13 15:31:27 +04:00
|
|
|
/* need to adjust multi-byte string pos */
|
1998-01-16 15:13:05 +03:00
|
|
|
if (flags&FWIDTH) {
|
|
|
|
if (width > len) {
|
|
|
|
CHECK(width);
|
1999-01-20 07:59:39 +03:00
|
|
|
width -= len;
|
1998-01-16 15:13:05 +03:00
|
|
|
if (!(flags&FMINUS)) {
|
|
|
|
while (width--) {
|
|
|
|
buf[blen++] = ' ';
|
|
|
|
}
|
|
|
|
}
|
2006-08-31 14:47:44 +04:00
|
|
|
memcpy(&buf[blen], RSTRING_PTR(str), len);
|
1998-01-16 15:13:05 +03:00
|
|
|
blen += len;
|
|
|
|
if (flags&FMINUS) {
|
|
|
|
while (width--) {
|
|
|
|
buf[blen++] = ' ';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-08-31 14:47:44 +04:00
|
|
|
PUSH(RSTRING_PTR(str), len);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
case 'd':
|
|
|
|
case 'i':
|
1998-01-16 15:13:05 +03:00
|
|
|
case 'o':
|
|
|
|
case 'x':
|
1999-01-20 07:59:39 +03:00
|
|
|
case 'X':
|
|
|
|
case 'b':
|
2001-10-22 10:48:18 +04:00
|
|
|
case 'B':
|
1998-01-16 15:13:05 +03:00
|
|
|
case 'u':
|
|
|
|
{
|
|
|
|
volatile VALUE val = GETARG();
|
|
|
|
char fbuf[32], nbuf[64], *s, *t;
|
2006-06-20 22:02:17 +04:00
|
|
|
const char *prefix = 0;
|
1999-01-20 07:59:39 +03:00
|
|
|
int sign = 0;
|
|
|
|
char sc = 0;
|
2003-01-16 21:48:20 +03:00
|
|
|
long v = 0;
|
1999-01-20 07:59:39 +03:00
|
|
|
int base, bignum = 0;
|
|
|
|
int len, pos;
|
|
|
|
|
|
|
|
switch (*p) {
|
|
|
|
case 'd':
|
|
|
|
case 'i':
|
2007-07-16 20:58:58 +04:00
|
|
|
case 'u':
|
1999-01-20 07:59:39 +03:00
|
|
|
sign = 1; break;
|
|
|
|
case 'o':
|
|
|
|
case 'x':
|
|
|
|
case 'X':
|
|
|
|
case 'b':
|
2001-10-22 10:48:18 +04:00
|
|
|
case 'B':
|
1999-01-20 07:59:39 +03:00
|
|
|
if (flags&(FPLUS|FSPACE)) sign = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (flags & FSHARP) {
|
2003-01-16 21:48:20 +03:00
|
|
|
switch (*p) {
|
|
|
|
case 'o':
|
|
|
|
prefix = "0"; break;
|
|
|
|
case 'x':
|
|
|
|
prefix = "0x"; break;
|
|
|
|
case 'X':
|
|
|
|
prefix = "0X"; break;
|
|
|
|
case 'b':
|
|
|
|
prefix = "0b"; break;
|
|
|
|
case 'B':
|
|
|
|
prefix = "0B"; break;
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
if (prefix) {
|
|
|
|
width -= strlen(prefix);
|
|
|
|
}
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
bin_retry:
|
|
|
|
switch (TYPE(val)) {
|
|
|
|
case T_FLOAT:
|
1999-01-20 07:59:39 +03:00
|
|
|
val = rb_dbl2big(RFLOAT(val)->value);
|
|
|
|
if (FIXNUM_P(val)) goto bin_retry;
|
1998-01-16 15:13:05 +03:00
|
|
|
bignum = 1;
|
|
|
|
break;
|
|
|
|
case T_STRING:
|
2002-02-01 13:23:22 +03:00
|
|
|
val = rb_str_to_inum(val, 0, Qtrue);
|
1998-01-16 15:13:05 +03:00
|
|
|
goto bin_retry;
|
|
|
|
case T_BIGNUM:
|
|
|
|
bignum = 1;
|
|
|
|
break;
|
2000-01-05 07:41:21 +03:00
|
|
|
case T_FIXNUM:
|
|
|
|
v = FIX2LONG(val);
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
2002-04-10 12:45:26 +04:00
|
|
|
default:
|
2002-06-04 11:34:19 +04:00
|
|
|
val = rb_Integer(val);
|
|
|
|
goto bin_retry;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2003-01-16 21:48:20 +03:00
|
|
|
switch (*p) {
|
|
|
|
case 'o':
|
|
|
|
base = 8; break;
|
|
|
|
case 'x':
|
|
|
|
case 'X':
|
|
|
|
base = 16; break;
|
|
|
|
case 'b':
|
|
|
|
case 'B':
|
|
|
|
base = 2; break;
|
|
|
|
case 'u':
|
|
|
|
case 'd':
|
|
|
|
case 'i':
|
|
|
|
default:
|
|
|
|
base = 10; break;
|
|
|
|
}
|
2004-02-18 04:24:13 +03:00
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
if (!bignum) {
|
1999-01-20 07:59:39 +03:00
|
|
|
if (base == 2) {
|
|
|
|
val = rb_int2big(v);
|
|
|
|
goto bin_retry;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
if (sign) {
|
|
|
|
char c = *p;
|
|
|
|
if (c == 'i') c = 'd'; /* %d and %i are identical */
|
1998-01-16 15:13:05 +03:00
|
|
|
if (v < 0) {
|
1999-01-20 07:59:39 +03:00
|
|
|
v = -v;
|
|
|
|
sc = '-';
|
|
|
|
width--;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
else if (flags & FPLUS) {
|
|
|
|
sc = '+';
|
|
|
|
width--;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
else if (flags & FSPACE) {
|
|
|
|
sc = ' ';
|
|
|
|
width--;
|
|
|
|
}
|
|
|
|
sprintf(fbuf, "%%l%c", c);
|
|
|
|
sprintf(nbuf, fbuf, v);
|
|
|
|
}
|
2004-02-18 04:24:13 +03:00
|
|
|
else {
|
|
|
|
s = nbuf;
|
|
|
|
if (v < 0) {
|
2007-07-16 20:58:58 +04:00
|
|
|
strcpy(s, "..");
|
|
|
|
s += 2;
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
2004-07-18 03:14:52 +04:00
|
|
|
sprintf(fbuf, "%%l%c", *p == 'X' ? 'x' : *p);
|
2004-02-18 04:24:13 +03:00
|
|
|
sprintf(s, fbuf, v);
|
|
|
|
if (v < 0) {
|
|
|
|
char d = 0;
|
|
|
|
|
|
|
|
remove_sign_bits(s, base);
|
|
|
|
switch (base) {
|
|
|
|
case 16:
|
|
|
|
d = 'f'; break;
|
|
|
|
case 8:
|
|
|
|
d = '7'; break;
|
|
|
|
}
|
|
|
|
if (d && *s != d) {
|
|
|
|
memmove(s+1, s, strlen(s)+1);
|
|
|
|
*s = d;
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
s = nbuf;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2004-02-18 04:24:13 +03:00
|
|
|
else {
|
|
|
|
if (sign) {
|
|
|
|
tmp = rb_big2str(val, base);
|
2006-08-31 14:47:44 +04:00
|
|
|
s = RSTRING_PTR(tmp);
|
2004-02-18 04:24:13 +03:00
|
|
|
if (s[0] == '-') {
|
|
|
|
s++;
|
|
|
|
sc = '-';
|
|
|
|
width--;
|
|
|
|
}
|
|
|
|
else if (flags & FPLUS) {
|
|
|
|
sc = '+';
|
|
|
|
width--;
|
|
|
|
}
|
|
|
|
else if (flags & FSPACE) {
|
|
|
|
sc = ' ';
|
|
|
|
width--;
|
|
|
|
}
|
2002-03-25 09:18:07 +03:00
|
|
|
}
|
|
|
|
else {
|
2005-12-12 18:09:50 +03:00
|
|
|
volatile VALUE tmp1;
|
2004-02-18 04:24:13 +03:00
|
|
|
if (!RBIGNUM(val)->sign) {
|
|
|
|
val = rb_big_clone(val);
|
|
|
|
rb_big_2comp(val);
|
2002-11-22 17:30:33 +03:00
|
|
|
}
|
2006-10-30 06:39:44 +03:00
|
|
|
tmp1 = tmp = rb_big2str0(val, base, RBIGNUM(val)->sign);
|
2006-08-31 14:47:44 +04:00
|
|
|
s = RSTRING_PTR(tmp);
|
2004-02-18 04:24:13 +03:00
|
|
|
if (*s == '-') {
|
|
|
|
if (base == 10) {
|
|
|
|
rb_warning("negative number for %%u specifier");
|
|
|
|
}
|
2006-07-26 12:28:57 +04:00
|
|
|
remove_sign_bits(++s, base);
|
|
|
|
tmp = rb_str_new(0, 3+strlen(s));
|
2006-08-31 14:47:44 +04:00
|
|
|
t = RSTRING_PTR(tmp);
|
2006-07-26 12:28:57 +04:00
|
|
|
if (!(flags&(FPREC|FZERO))) {
|
|
|
|
strcpy(t, "..");
|
|
|
|
t += 2;
|
2004-02-18 04:24:13 +03:00
|
|
|
}
|
2006-07-26 12:28:57 +04:00
|
|
|
switch (base) {
|
|
|
|
case 16:
|
|
|
|
if (s[0] != 'f') strcpy(t++, "f"); break;
|
|
|
|
case 8:
|
|
|
|
if (s[0] != '7') strcpy(t++, "7"); break;
|
|
|
|
case 2:
|
|
|
|
if (s[0] != '1') strcpy(t++, "1"); break;
|
|
|
|
}
|
|
|
|
strcpy(t, s);
|
2006-08-31 14:47:44 +04:00
|
|
|
s = RSTRING_PTR(tmp);
|
2002-04-10 12:45:26 +04:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
pos = -1;
|
|
|
|
len = strlen(s);
|
|
|
|
|
|
|
|
if (*p == 'X') {
|
|
|
|
char *pp = s;
|
|
|
|
while (*pp) {
|
|
|
|
*pp = toupper(*pp);
|
|
|
|
pp++;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
2002-12-10 09:23:44 +03:00
|
|
|
if ((flags&(FZERO|FPREC)) == FZERO) {
|
|
|
|
prec = width;
|
|
|
|
width = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (prec < len) prec = len;
|
|
|
|
width -= prec;
|
|
|
|
}
|
|
|
|
if (!(flags&FMINUS)) {
|
1999-01-20 07:59:39 +03:00
|
|
|
CHECK(width);
|
2002-12-10 09:23:44 +03:00
|
|
|
while (width-- > 0) {
|
1999-01-20 07:59:39 +03:00
|
|
|
buf[blen++] = ' ';
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
if (sc) PUSH(&sc, 1);
|
|
|
|
if (prefix) {
|
|
|
|
int plen = strlen(prefix);
|
2001-01-10 12:52:13 +03:00
|
|
|
PUSH(prefix, plen);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
CHECK(prec - len);
|
2003-01-16 21:48:20 +03:00
|
|
|
if (!bignum && v < 0) {
|
2003-03-20 09:27:22 +03:00
|
|
|
char c = sign_bits(base, p);
|
2002-12-10 09:23:44 +03:00
|
|
|
while (len < prec--) {
|
|
|
|
buf[blen++] = c;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
2002-12-10 09:23:44 +03:00
|
|
|
else {
|
2003-03-20 20:01:30 +03:00
|
|
|
char c;
|
|
|
|
|
2004-02-20 13:03:47 +03:00
|
|
|
if (!sign && bignum && !RBIGNUM(val)->sign)
|
2003-03-20 20:01:30 +03:00
|
|
|
c = sign_bits(base, p);
|
|
|
|
else
|
|
|
|
c = '0';
|
2002-12-10 09:23:44 +03:00
|
|
|
while (len < prec--) {
|
2003-03-20 09:27:22 +03:00
|
|
|
buf[blen++] = c;
|
2002-12-10 09:23:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
PUSH(s, len);
|
|
|
|
CHECK(width);
|
|
|
|
while (width-- > 0) {
|
|
|
|
buf[blen++] = ' ';
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'f':
|
|
|
|
case 'g':
|
1999-08-13 09:45:20 +04:00
|
|
|
case 'G':
|
1998-01-16 15:13:05 +03:00
|
|
|
case 'e':
|
1999-01-20 07:59:39 +03:00
|
|
|
case 'E':
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
VALUE val = GETARG();
|
|
|
|
double fval;
|
1999-08-13 09:45:20 +04:00
|
|
|
int i, need = 6;
|
1998-01-16 15:13:05 +03:00
|
|
|
char fbuf[32];
|
|
|
|
|
2001-09-03 09:37:42 +04:00
|
|
|
fval = RFLOAT(rb_Float(val))->value;
|
2004-06-22 14:28:12 +04:00
|
|
|
if (isnan(fval) || isinf(fval)) {
|
2006-06-20 22:02:17 +04:00
|
|
|
const char *expr;
|
2004-06-22 14:28:12 +04:00
|
|
|
|
|
|
|
if (isnan(fval)) {
|
|
|
|
expr = "NaN";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
expr = "Inf";
|
|
|
|
}
|
|
|
|
need = strlen(expr);
|
2004-06-22 18:38:21 +04:00
|
|
|
if ((!isnan(fval) && fval < 0.0) || (flags & FPLUS))
|
2004-06-22 14:28:12 +04:00
|
|
|
need++;
|
|
|
|
if ((flags & FWIDTH) && need < width)
|
|
|
|
need = width;
|
|
|
|
|
|
|
|
CHECK(need);
|
|
|
|
sprintf(&buf[blen], "%*s", need, "");
|
|
|
|
if (flags & FMINUS) {
|
2004-06-22 18:38:21 +04:00
|
|
|
if (!isnan(fval) && fval < 0.0)
|
2004-06-22 14:28:12 +04:00
|
|
|
buf[blen++] = '-';
|
|
|
|
else if (flags & FPLUS)
|
|
|
|
buf[blen++] = '+';
|
2004-06-22 18:38:21 +04:00
|
|
|
else if (flags & FSPACE)
|
|
|
|
blen++;
|
|
|
|
strncpy(&buf[blen], expr, strlen(expr));
|
|
|
|
}
|
|
|
|
else if (flags & FZERO) {
|
|
|
|
if (!isnan(fval) && fval < 0.0) {
|
|
|
|
buf[blen++] = '-';
|
|
|
|
need--;
|
|
|
|
}
|
|
|
|
else if (flags & FPLUS) {
|
|
|
|
buf[blen++] = '+';
|
|
|
|
need--;
|
|
|
|
}
|
|
|
|
else if (flags & FSPACE) {
|
|
|
|
blen++;
|
|
|
|
need--;
|
|
|
|
}
|
|
|
|
while (need-- - strlen(expr) > 0) {
|
|
|
|
buf[blen++] = '0';
|
|
|
|
}
|
2004-06-22 14:28:12 +04:00
|
|
|
strncpy(&buf[blen], expr, strlen(expr));
|
|
|
|
}
|
|
|
|
else {
|
2004-06-22 18:38:21 +04:00
|
|
|
if (!isnan(fval) && fval < 0.0)
|
2004-06-22 14:28:12 +04:00
|
|
|
buf[blen + need - strlen(expr) - 1] = '-';
|
|
|
|
else if (flags & FPLUS)
|
|
|
|
buf[blen + need - strlen(expr) - 1] = '+';
|
|
|
|
strncpy(&buf[blen + need - strlen(expr)], expr,
|
|
|
|
strlen(expr));
|
|
|
|
}
|
|
|
|
blen += strlen(&buf[blen]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
fmt_setup(fbuf, *p, flags, width, prec);
|
1999-08-13 09:45:20 +04:00
|
|
|
need = 0;
|
|
|
|
if (*p != 'e' && *p != 'E') {
|
|
|
|
i = INT_MIN;
|
|
|
|
frexp(fval, &i);
|
|
|
|
if (i > 0)
|
|
|
|
need = BIT_DIGITS(i);
|
|
|
|
}
|
|
|
|
need += (flags&FPREC) ? prec : 6;
|
|
|
|
if ((flags&FWIDTH) && need < width)
|
|
|
|
need = width;
|
|
|
|
need += 20;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
CHECK(need);
|
1998-01-16 15:13:05 +03:00
|
|
|
sprintf(&buf[blen], fbuf, fval);
|
|
|
|
blen += strlen(&buf[blen]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
flags = FNONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
sprint_exit:
|
2004-10-27 13:29:26 +04:00
|
|
|
/* XXX - We cannot validiate the number of arguments if (digit)$ style used.
|
1999-11-11 07:08:26 +03:00
|
|
|
*/
|
2005-06-07 12:22:42 +04:00
|
|
|
if (posarg >= 0 && nextarg < argc) {
|
|
|
|
const char *mesg = "too many arguments for format string";
|
|
|
|
if (RTEST(ruby_debug)) rb_raise(rb_eArgError, mesg);
|
|
|
|
if (RTEST(ruby_verbose)) rb_warn(mesg);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2002-10-16 17:44:19 +04:00
|
|
|
rb_str_resize(result, blen);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-12-06 12:04:03 +03:00
|
|
|
if (tainted) OBJ_TAINT(result);
|
1998-01-16 15:13:05 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
fmt_setup(char *buf, int c, int flags, int width, int prec)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
*buf++ = '%';
|
|
|
|
if (flags & FSHARP) *buf++ = '#';
|
|
|
|
if (flags & FPLUS) *buf++ = '+';
|
|
|
|
if (flags & FMINUS) *buf++ = '-';
|
|
|
|
if (flags & FZERO) *buf++ = '0';
|
1999-01-20 07:59:39 +03:00
|
|
|
if (flags & FSPACE) *buf++ = ' ';
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
if (flags & FWIDTH) {
|
|
|
|
sprintf(buf, "%d", width);
|
|
|
|
buf += strlen(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & FPREC) {
|
|
|
|
sprintf(buf, ".%d", prec);
|
|
|
|
buf += strlen(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
*buf++ = c;
|
|
|
|
*buf = '\0';
|
|
|
|
}
|
2005-07-23 05:02:18 +04:00
|
|
|
|
|
|
|
#undef FILE
|
|
|
|
#define FILE rb_printf_buffer
|
|
|
|
#define __sbuf rb_printf_sbuf
|
|
|
|
#define __sFILE rb_printf_sfile
|
|
|
|
#undef feof
|
|
|
|
#undef ferror
|
2005-07-28 16:49:31 +04:00
|
|
|
#undef clearerr
|
2005-07-23 05:02:18 +04:00
|
|
|
#undef fileno
|
2005-07-27 11:27:19 +04:00
|
|
|
#if SIZEOF_LONG < SIZEOF_VOIDP
|
|
|
|
# if SIZEOF_LONG_LONG == SIZEOF_VOIDP
|
|
|
|
# define _HAVE_SANE_QUAD_
|
|
|
|
# define _HAVE_LLP64_
|
2005-07-27 18:30:09 +04:00
|
|
|
# define quad_t LONG_LONG
|
2005-07-27 11:27:19 +04:00
|
|
|
# define u_quad_t unsigned LONG_LONG
|
|
|
|
# endif
|
|
|
|
#endif
|
2005-08-03 05:05:30 +04:00
|
|
|
#undef vsnprintf
|
|
|
|
#undef snprintf
|
2005-07-23 05:02:18 +04:00
|
|
|
#include "missing/vsnprintf.c"
|
|
|
|
|
|
|
|
static int
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
ruby__sfvwrite(register rb_printf_buffer *fp, register struct __suio *uio)
|
2005-07-23 05:02:18 +04:00
|
|
|
{
|
|
|
|
struct __siov *iov;
|
|
|
|
VALUE result = (VALUE)fp->_bf._base;
|
2005-07-28 06:33:28 +04:00
|
|
|
char *buf = (char*)fp->_p;
|
2005-07-23 05:02:18 +04:00
|
|
|
size_t len, n;
|
2006-08-31 14:47:44 +04:00
|
|
|
int blen = buf - RSTRING_PTR(result), bsiz = fp->_w;
|
2005-07-23 05:02:18 +04:00
|
|
|
|
|
|
|
if (RBASIC(result)->klass) {
|
|
|
|
rb_raise(rb_eRuntimeError, "rb_vsprintf reentered");
|
|
|
|
}
|
|
|
|
if ((len = uio->uio_resid) == 0)
|
|
|
|
return 0;
|
|
|
|
CHECK(len);
|
2005-08-22 20:21:27 +04:00
|
|
|
buf += blen;
|
2005-07-23 05:02:18 +04:00
|
|
|
fp->_w = bsiz;
|
|
|
|
for (iov = uio->uio_iov; len > 0; ++iov) {
|
|
|
|
MEMCPY(buf, iov->iov_base, char, n = iov->iov_len);
|
|
|
|
buf += n;
|
|
|
|
len -= n;
|
|
|
|
}
|
|
|
|
fp->_p = (unsigned char *)buf;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_vsprintf(const char *fmt, va_list ap)
|
2005-07-23 05:02:18 +04:00
|
|
|
{
|
|
|
|
rb_printf_buffer f;
|
|
|
|
VALUE result;
|
|
|
|
|
|
|
|
f._flags = __SWR | __SSTR;
|
|
|
|
f._bf._size = 0;
|
|
|
|
f._w = 120;
|
|
|
|
result = rb_str_buf_new(f._w);
|
|
|
|
f._bf._base = (unsigned char *)result;
|
2006-08-31 14:47:44 +04:00
|
|
|
f._p = (unsigned char *)RSTRING_PTR(result);
|
2005-07-23 05:02:18 +04:00
|
|
|
RBASIC(result)->klass = 0;
|
|
|
|
f.vwrite = ruby__sfvwrite;
|
|
|
|
BSD_vfprintf(&f, fmt, ap);
|
|
|
|
RBASIC(result)->klass = rb_cString;
|
2006-08-31 14:47:44 +04:00
|
|
|
rb_str_resize(result, (char *)f._p - RSTRING_PTR(result));
|
2005-07-23 05:02:18 +04:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_sprintf(const char *format, ...)
|
|
|
|
{
|
|
|
|
VALUE result;
|
|
|
|
va_list ap;
|
|
|
|
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
va_start(ap, format);
|
2005-07-23 05:02:18 +04:00
|
|
|
result = rb_vsprintf(format, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|