Ruby 2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)

Data Structures | Macros | Functions
sprintf.c File Reference
`#include "ruby/encoding.h"`
`#include "ruby/re.h"`
`#include "internal.h"`
`#include "id.h"`
`#include <math.h>`
`#include <stdarg.h>`
`#include "vsnprintf.c"`

Go to the source code of this file.

## Data Structures
struct | rb_printf_buffer_extra

## Macros
#define | BIT_DIGITS(N) (((N)*146)/485 + 1) /* log2(10) =~ 146/485 */
#define | FNONE 0
#define | FSHARP 1
#define | FMINUS 2
#define | FPLUS 4
#define | FZERO 8
#define | FSPACE 16
#define | FWIDTH 32
#define | FPREC 64
#define | FPREC0 128
#define | CHECK(l)
#define | PUSH(s, l)
#define | PUSH_(s, l)
#define | FILL(c, l)
#define | FILL_(c, l)
#define | GETARG()
#define | GETNEXTARG()
#define | GETPOSARG(n)
#define | GETNTHARG(nth) (((nth) >= argc) ? (rb_raise(rb_eArgError, "too few arguments"), 0) : argv[(nth)])
#define | CHECKNAMEARG(name, len, enc)
#define | GETNUM(n, val)
#define | GETASTER(val)
#define | CHECK_FOR_WIDTH(f)
#define | CHECK_FOR_FLAGS(f)
#define | FILE rb_printf_buffer
#define | __sbuf rb_printf_sbuf
#define | __sFILE rb_printf_sfile
#define | FLOATING_POINT 1
#define | BSD__dtoa ruby_dtoa
#define | BSD__hdtoa ruby_hdtoa
#define | PRI_EXTRA_MARK RUBY_PRI_VALUE_MARK
#define | lower_hexdigits (ruby_hexdigits+0)
#define | upper_hexdigits (ruby_hexdigits+16)
#define | LITERAL(str) (*sz = rb_strlen_lit(str), str)
#define | f buffer.base

## Functions
VALUE | rb_f_sprintf (int argc, const VALUE *argv)
VALUE | rb_str_format (int argc, const VALUE *argv, VALUE fmt)
int | ruby_vsnprintf (char *str, size_t n, const char *fmt, va_list ap)
int | ruby_snprintf (char *str, size_t n, char const *fmt,...)
VALUE | rb_enc_vsprintf (rb_encoding *enc, const char *fmt, va_list ap)
VALUE | rb_enc_sprintf (rb_encoding *enc, const char *format,...)
VALUE | rb_vsprintf (const char *fmt, va_list ap)
VALUE | rb_sprintf (const char *format,...)
VALUE | rb_str_vcatf (VALUE str, const char *fmt, va_list ap)
VALUE | rb_str_catf (VALUE str, const char *format,...)

## Macro Definition Documentation

## ◆ __sbuf

#define __sbuf rb_printf_sbuf

Definition at line 961 of file sprintf.c.

## ◆ __sFILE

#define __sFILE rb_printf_sfile

Definition at line 962 of file sprintf.c.

## ◆ BIT_DIGITS

#define BIT_DIGITS | ( |  | N | ) | (((N)*146)/485 + 1) /* log2(10) =~ 146/485 */

Definition at line 25 of file sprintf.c.

## ◆ BSD__dtoa

#define BSD__dtoa ruby_dtoa

Definition at line 980 of file sprintf.c.

## ◆ BSD__hdtoa

#define BSD__hdtoa ruby_hdtoa

Definition at line 981 of file sprintf.c.

## ◆ CHECK

#define CHECK | ( |  | l | ) |

Value:
do {\
int cr = ENC_CODERANGE(result);\
while ((l) >= bsiz - blen) {\
bsiz*=2;\
if (bsiz<0) rb_raise(rb_eArgError, "too big specifier");\
}\
rb_str_resize(result, bsiz);\
ENC_CODERANGE_SET(result, cr);\
buf = RSTRING_PTR(result);\
} while (0)

Definition at line 58 of file sprintf.c.

## ◆ CHECK_FOR_FLAGS

#define CHECK_FOR_FLAGS | ( |  | f | ) |

Value:
if ((f) & FWIDTH) { \
rb_raise(rb_eArgError, "flag after width"); \
} \
if ((f) & FPREC0) { \
rb_raise(rb_eArgError, "flag after precision"); \
}

## ◆ CHECK_FOR_WIDTH

#define CHECK_FOR_WIDTH | ( |  | f | ) |

Value:
if ((f) & FWIDTH) { \
rb_raise(rb_eArgError, "width given twice"); \
} \
if ((f) & FPREC0) { \
rb_raise(rb_eArgError, "width after precision"); \
}

## ◆ CHECKNAMEARG

#define CHECKNAMEARG | ( |  | name,
|  |  | len,
|  |  | enc
| ) |  |

Value:
( \
check_name_arg(posarg, name, len, enc), \
posarg = -2)

Definition at line 104 of file sprintf.c.

## ◆ f [1/2]

#define f buffer.base

## ◆ f [2/2]

#define f buffer.base

## ◆ FILE

#define FILE rb_printf_buffer

Definition at line 960 of file sprintf.c.

## ◆ FILL

#define FILL | ( |  | c,
|  |  | l
| ) |  |

Value:
do { \
if ((l) <= 0) break;\
CHECK(l);\
FILL_(c, l);\
} while (0)

Definition at line 79 of file sprintf.c.

## ◆ FILL_

#define FILL_ | ( |  | c,
|  |  | l
| ) |  |

Value:
do { \
memset(&buf[blen], (c), (l));\
blen += (l);\
} while (0)

Definition at line 85 of file sprintf.c.

## ◆ FLOATING_POINT

#define FLOATING_POINT 1

Definition at line 979 of file sprintf.c.

## ◆ FMINUS

#define FMINUS 2

Definition at line 50 of file sprintf.c.

## ◆ FNONE

#define FNONE 0

Definition at line 48 of file sprintf.c.

## ◆ FPLUS

#define FPLUS 4

Definition at line 51 of file sprintf.c.

## ◆ FPREC

#define FPREC 64

Definition at line 55 of file sprintf.c.

## ◆ FPREC0

#define FPREC0 128

Definition at line 56 of file sprintf.c.

## ◆ FSHARP

#define FSHARP 1

Definition at line 49 of file sprintf.c.

## ◆ FSPACE

#define FSPACE 16

Definition at line 53 of file sprintf.c.

## ◆ FWIDTH

#define FWIDTH 32

Definition at line 54 of file sprintf.c.

## ◆ FZERO

#define FZERO 8

Definition at line 52 of file sprintf.c.

## ◆ GETARG

#define GETARG | ( |  | ) |

Value:
(nextvalue != Qundef ? nextvalue : \
GETNEXTARG())

Definition at line 90 of file sprintf.c.

## ◆ GETASTER

#define GETASTER | ( |  | val | ) |

Value:
do { \
t = p++; \
n = 0; \
GETNUM(n, val); \
if (*p == '$') { \
tmp = GETPOSARG(n); \
} \
else { \
tmp = GETNEXTARG(); \
p = t; \
} \
(val) = NUM2INT(tmp); \
} while (0)

Definition at line 112 of file sprintf.c.

## ◆ GETNEXTARG

#define GETNEXTARG | ( |  | ) |

Value:
( \
check_next_arg(posarg, nextarg), \
(posarg = nextarg++, GETNTHARG(posarg)))

Definition at line 93 of file sprintf.c.

## ◆ GETNTHARG

#define GETNTHARG | ( |  | nth | ) | (((nth) >= argc) ? (rb_raise(rb_eArgError, "too few arguments"), 0) : argv[(nth)])

Definition at line 101 of file sprintf.c.

## ◆ GETNUM

#define GETNUM | ( |  | n,
|  |  | val
| ) |  |

Value:
(!(p = get_num(p, end, enc, &(n))) ? \
rb_raise(rb_eArgError, #val " too big") : (void)0)

Definition at line 108 of file sprintf.c.

## ◆ GETPOSARG

#define GETPOSARG | ( |  | n | ) |

Value:
( \
check_pos_arg(posarg, (n)), \
(posarg = -1, GETNTHARG(n)))

Definition at line 97 of file sprintf.c.

## ◆ LITERAL

#define LITERAL | ( |  | str | ) | (*sz = rb_strlen_lit(str), str)

## ◆ lower_hexdigits

#define lower_hexdigits (ruby_hexdigits+0)

Definition at line 985 of file sprintf.c.

## ◆ PRI_EXTRA_MARK

#define PRI_EXTRA_MARK RUBY_PRI_VALUE_MARK

Definition at line 983 of file sprintf.c.

## ◆ PUSH

#define PUSH | ( |  | s,
|  |  | l
| ) |  |

Value:
do { \
CHECK(l);\
PUSH_(s, l);\
} while (0)

Definition at line 69 of file sprintf.c.

## ◆ PUSH_

#define PUSH_ | ( |  | s,
|  |  | l
| ) |  |

Value:
do { \
memcpy(&buf[blen], (s), (l));\
blen += (l);\
} while (0)

Definition at line 74 of file sprintf.c.

## ◆ upper_hexdigits

#define upper_hexdigits (ruby_hexdigits+16)

Definition at line 986 of file sprintf.c.

## Function Documentation

## ◆ rb_enc_sprintf()

VALUE rb_enc_sprintf | ( | rb_encoding * | enc,
|  | const char * | format,
|  |  | ...
| ) |  |

Definition at line 1178 of file sprintf.c.

## ◆ rb_enc_vsprintf()

VALUE rb_enc_vsprintf | ( | rb_encoding * | enc,
|  | const char * | fmt,
|  | va_list | ap
| ) |  |

Definition at line 1145 of file sprintf.c.

Referenced by rb_enc_raise(), rb_loaderror(), rb_loaderror_with_path(), and rb_vsprintf().

## ◆ rb_f_sprintf()

VALUE rb_f_sprintf | ( | int | argc,
|  | const VALUE * | argv
| ) |  |

Definition at line 198 of file sprintf.c.

References argc, argv, GETNTHARG, and rb_str_format().

Referenced by rb_io_printf().

## ◆ rb_sprintf()

VALUE rb_sprintf | ( | const char * | format,
|  |  | ...
| ) |  |

Definition at line 1197 of file sprintf.c.

Referenced by rb_any_to_s(), rb_block_to_s(), rb_error_frozen_object(), rb_insn_operand_intern(), rb_keyword_error_new(), rb_parser_show_bitstack(), rb_profile_frame_full_label(), rsock_syserr_fail_host_port(), rsock_syserr_fail_path(), rsock_syserr_fail_raddrinfo(), and ruby_setenv().

## ◆ rb_str_catf()

VALUE rb_str_catf | ( | VALUE | str,
|  | const char * | format,
|  |  | ...
| ) |  |

Definition at line 1237 of file sprintf.c.

References rb_str_vcatf(), str, va_end, and va_start.

Referenced by rb_iseq_disasm_insn(), and rsock_inspect_sockaddr().

## ◆ rb_str_format()

VALUE rb_str_format | ( | int | argc,
|  | const VALUE * | argv,
|  | VALUE | fmt
| ) |  |

Definition at line 204 of file sprintf.c.

References buf, and rb_encoding.

Referenced by rb_f_sprintf().

## ◆ rb_str_vcatf()

VALUE rb_str_vcatf | ( | VALUE | str,
|  | const char * | fmt,
|  | va_list | ap
| ) |  |

Definition at line 1210 of file sprintf.c.

References __SSTR, __SWR, f, klass, rb_str_capacity(), rb_str_modify(), RBASIC, RBASIC_CLEAR_CLASS, RSTRING_END, str, and StringValue().

Referenced by rb_parser_fatal(), rb_parser_printf(), and rb_str_catf().

## ◆ rb_vsprintf()

VALUE rb_vsprintf | ( | const char * | fmt,
|  | va_list | ap
| ) |  |

Definition at line 1191 of file sprintf.c.

References fmt, NULL, and rb_enc_vsprintf().

Referenced by rb_frozen_error_raise(), rb_name_error(), rb_name_error_str(), and rb_vraise().

## ◆ ruby_snprintf()

int ruby_snprintf | ( | char * | str,
|  | size_t | n,
|  | char const * | fmt,
|  |  | ...
| ) |  |

Definition at line 1031 of file sprintf.c.

References EOF, fmt, n, str, and va_start.

void
void
Definition: rb_mjit_min_header-2.7.0.h:13273
GETNTHARG
#define GETNTHARG(nth)
Definition: sprintf.c:101
RSTRING_PTR
#define RSTRING_PTR(str)
Definition: ruby.h:1009
rb_eArgError
VALUE rb_eArgError
Definition: error.c:923
GETNEXTARG
#define GETNEXTARG()
Definition: sprintf.c:93
Qundef
#define Qundef
Definition: ruby.h:470
ENC_CODERANGE_SET
#define ENC_CODERANGE_SET(obj, cr)
Definition: encoding.h:110
rb_str_resize
VALUE rb_str_resize(VALUE, long)
Definition: string.c:2709
rb_raise
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:2669
FPREC0
#define FPREC0
Definition: sprintf.c:56
CHECK
#define CHECK(l)
Definition: sprintf.c:58
n
const char size_t n
Definition: rb_mjit_min_header-2.7.0.h:5456
buf
unsigned char buf[MIME_BUF_SIZE]
Definition: nkf.c:4322
f
#define f
len
uint8_t len
Definition: escape.c:17
ENC_CODERANGE
#define ENC_CODERANGE(obj)
Definition: encoding.h:108
GETPOSARG
#define GETPOSARG(n)
Definition: sprintf.c:97
FILL_
#define FILL_(c, l)
Definition: sprintf.c:85
FWIDTH
#define FWIDTH
Definition: sprintf.c:54
NUM2INT
#define NUM2INT(x)
Definition: ruby.h:715
name
const char * name
Definition: nkf.c:208
get_num
#define get_num(num)
Definition: ripper.c:589