Ruby  2.5.0dev(2017-10-22revision60238)
Data Structures | Macros | Functions
sprintf.c File Reference
#include "internal.h"
#include "ruby/re.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
 
#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 1224 of file sprintf.c.

◆ __sFILE

#define __sFILE   rb_printf_sfile

Definition at line 1225 of file sprintf.c.

◆ BIT_DIGITS

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

Definition at line 24 of file sprintf.c.

◆ BSD__dtoa

#define BSD__dtoa   ruby_dtoa

Definition at line 1243 of file sprintf.c.

◆ BSD__hdtoa

#define BSD__hdtoa   ruby_hdtoa

Definition at line 1244 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)
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:2284
#define ENC_CODERANGE_SET(obj, cr)
Definition: encoding.h:106
VALUE rb_eArgError
Definition: error.c:802
VALUE rb_str_resize(VALUE, long)
Definition: string.c:2644
unsigned char buf[MIME_BUF_SIZE]
Definition: nkf.c:4309
#define RSTRING_PTR(str)
Definition: ruby.h:975
#define ENC_CODERANGE(obj)
Definition: encoding.h:104

Definition at line 57 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"); \
}
VALUE rb_eArgError
Definition: error.c:802
#define FPREC0
Definition: sprintf.c:55
#define f
#define FWIDTH
Definition: sprintf.c:53

◆ 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"); \
}
VALUE rb_eArgError
Definition: error.c:802
#define FPREC0
Definition: sprintf.c:55
#define f
#define FWIDTH
Definition: sprintf.c:53

◆ CHECKNAMEARG

#define CHECKNAMEARG (   name,
  len,
  enc 
)
Value:
( \
check_name_arg(posarg, name, len, enc), \
posarg = -2)
register unsigned int len
Definition: zonetab.h:51
const char * name
Definition: nkf.c:208

Definition at line 103 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 1223 of file sprintf.c.

◆ FILL

#define FILL (   c,
 
)
Value:
do { \
if ((l) <= 0) break;\
CHECK(l);\
FILL_(c, l);\
} while (0)
#define CHECK(l)
Definition: sprintf.c:57
#define FILL_(c, l)
Definition: sprintf.c:84

Definition at line 78 of file sprintf.c.

◆ FILL_

#define FILL_ (   c,
 
)
Value:
do { \
memset(&buf[blen], (c), (l));\
blen += (l);\
} while (0)
unsigned char buf[MIME_BUF_SIZE]
Definition: nkf.c:4309

Definition at line 84 of file sprintf.c.

◆ FLOATING_POINT

#define FLOATING_POINT   1

Definition at line 1242 of file sprintf.c.

◆ FMINUS

#define FMINUS   2

Definition at line 49 of file sprintf.c.

◆ FNONE

#define FNONE   0

Definition at line 47 of file sprintf.c.

◆ FPLUS

#define FPLUS   4

Definition at line 50 of file sprintf.c.

◆ FPREC

#define FPREC   64

Definition at line 54 of file sprintf.c.

◆ FPREC0

#define FPREC0   128

Definition at line 55 of file sprintf.c.

◆ FSHARP

#define FSHARP   1

Definition at line 48 of file sprintf.c.

◆ FSPACE

#define FSPACE   16

Definition at line 52 of file sprintf.c.

◆ FWIDTH

#define FWIDTH   32

Definition at line 53 of file sprintf.c.

◆ FZERO

#define FZERO   8

Definition at line 51 of file sprintf.c.

◆ GETARG

#define GETARG ( )
Value:
(nextvalue != Qundef ? nextvalue : \
GETNEXTARG())
#define Qundef
Definition: ruby.h:439

Definition at line 89 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)
#define NUM2INT(x)
Definition: ruby.h:684
#define GETNEXTARG()
Definition: sprintf.c:92
#define val
#define GETPOSARG(n)
Definition: sprintf.c:96

Definition at line 111 of file sprintf.c.

◆ GETNEXTARG

#define GETNEXTARG ( )
Value:
( \
check_next_arg(posarg, nextarg), \
(posarg = nextarg++, GETNTHARG(posarg)))
#define GETNTHARG(nth)
Definition: sprintf.c:100

Definition at line 92 of file sprintf.c.

◆ GETNTHARG

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

Definition at line 100 of file sprintf.c.

Referenced by rb_f_sprintf().

◆ GETNUM

#define GETNUM (   n,
  val 
)
Value:
(!(p = get_num(p, end, enc, &(n))) ? \
rb_raise(rb_eArgError, #val " too big") : (void)0)
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:2284
VALUE rb_eArgError
Definition: error.c:802
#define val

Definition at line 107 of file sprintf.c.

◆ GETPOSARG

#define GETPOSARG (   n)
Value:
( \
check_pos_arg(posarg, (n)), \
(posarg = -1, GETNTHARG(n)))
#define GETNTHARG(nth)
Definition: sprintf.c:100

Definition at line 96 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 1248 of file sprintf.c.

◆ PRI_EXTRA_MARK

#define PRI_EXTRA_MARK   RUBY_PRI_VALUE_MARK

Definition at line 1246 of file sprintf.c.

◆ PUSH

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

Definition at line 68 of file sprintf.c.

◆ PUSH_

#define PUSH_ (   s,
 
)
Value:
do { \
memcpy(&buf[blen], (s), (l));\
blen += (l);\
} while (0)
unsigned char buf[MIME_BUF_SIZE]
Definition: nkf.c:4309

Definition at line 73 of file sprintf.c.

◆ upper_hexdigits

#define upper_hexdigits   (ruby_hexdigits+16)

Definition at line 1249 of file sprintf.c.

Function Documentation

◆ rb_enc_sprintf()

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

Definition at line 1433 of file sprintf.c.

◆ rb_enc_vsprintf()

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

Definition at line 1400 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 458 of file sprintf.c.

References GETNTHARG, and rb_str_format().

Referenced by rb_io_printf().

◆ rb_sprintf()

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

◆ rb_str_catf()

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

Definition at line 1492 of file sprintf.c.

References rb_str_vcatf().

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 464 of file sprintf.c.

References buf.

Referenced by rb_f_sprintf().

◆ rb_str_vcatf()

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

◆ rb_vsprintf()

VALUE rb_vsprintf ( const char *  fmt,
va_list  ap 
)

Definition at line 1446 of file sprintf.c.

References NULL, and rb_enc_vsprintf().

Referenced by rb_fatal(), rb_name_error(), rb_name_error_str(), and rb_raise().

◆ ruby_snprintf()

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

Definition at line 1291 of file sprintf.c.

References EOF.

◆ ruby_vsnprintf()

int ruby_vsnprintf ( char *  str,
size_t  n,
const char *  fmt,
va_list  ap 
)

Definition at line 1267 of file sprintf.c.

References EOF.