Ruby 2.0.0p247(2013-06-27revision41674)

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

Macros | Functions
strftime.c File Reference
`#include "ruby/ruby.h"`
`#include "ruby/encoding.h"`
`#include "timev.h"`
`#include <stdio.h>`
`#include <ctype.h>`
`#include <string.h>`
`#include <time.h>`
`#include <sys/types.h>`
`#include <errno.h>`
`#include <math.h>`
Include dependency graph for strftime.c:

Go to the source code of this file.

## Macros
#define | SYSV_EXT 1 /* stuff in System V ascftime routine */
#define | SUNOS_EXT 1 /* stuff in SunOS strftime routine */
#define | POSIX2_DATE 1 /* stuff in Posix 1003.2 date command */
#define | VMS_EXT 1 /* include %v for VMS date format */
#define | MAILHEADER_EXT 1 /* add %z for HHMM format */
#define | ISO_DATE_EXT 1 /* %G and %g for year of ISO week */
#define | adddecl(stuff) stuff
#define | const
#define | range(low, item, hi) max((low), min((item), (hi)))
#define | add(x, y) (rb_funcall((x), '+', 1, (y)))
#define | sub(x, y) (rb_funcall((x), '-', 1, (y)))
#define | mul(x, y) (rb_funcall((x), '*', 1, (y)))
#define | quo(x, y) (rb_funcall((x), rb_intern("quo"), 1, (y)))
#define | div(x, y) (rb_funcall((x), rb_intern("div"), 1, (y)))
#define | mod(x, y) (rb_funcall((x), '%', 1, (y)))
#define | TBUFSIZE 100
#define | BIT_OF(n) (1U<<(n))
#define | FLAG_FOUND()
#define | NEEDS(n) do if (s >= endp || (n) >= endp - s - 1) goto err; while (0)
#define | FILL_PADDING(i)
#define | FMT(def_pad, def_prec, fmt, val)
#define | STRFTIME(fmt)
#define | FMTV(def_pad, def_prec, fmt, val)

## Functions
static int | weeknumber ()
| adddecl (static int iso8601wknum();)
static int | max (int a, int b)
static size_t | rb_strftime_with_timespec (char *s, size_t maxsize, const char *format, rb_encoding *enc, const struct vtm *vtm, VALUE timev, struct timespec *ts, int gmt)
size_t | rb_strftime (char *s, size_t maxsize, const char *format, rb_encoding *enc, const struct vtm *vtm, VALUE timev, int gmt)
size_t | rb_strftime_timespec (char *s, size_t maxsize, const char *format, rb_encoding *enc, const struct vtm *vtm, struct timespec *ts, int gmt)
static int | isleap (long year)
static void | vtm2tm_noyear (const struct vtm *vtm, struct tm *result)
static int | iso8601wknum (const struct tm *timeptr)
static int | iso8601wknum_v (const struct vtm *vtm)
static int | weeknumber (const struct tm *timeptr, int firstweekday)
static int | weeknumber_v (const struct vtm *vtm, int firstweekday)

## Macro Definition Documentation

#define add | ( |  | x,
|  |  | y
| ) |  | (rb_funcall((x), '+', 1, (y)))

Definition at line 150 of file strftime.c.

Referenced by rb_strftime_with_timespec().

#define adddecl | ( |  | stuff) |  | stuff

Definition at line 94 of file strftime.c.

#define BIT_OF | ( |  | n) |  | (1U<<(n))

#define const

Definition at line 102 of file strftime.c.

#define div | ( |  | x,
|  |  | y
| ) |  | (rb_funcall((x), rb_intern("div"), 1, (y)))

Definition at line 154 of file strftime.c.

Referenced by rb_strftime_with_timespec().

#define FILL_PADDING | ( |  | i) |  |

Value:
do { \
if (!(flags & BIT_OF(LEFT)) && precision > (i)) { \
NEEDS(precision); \
memset(s, padding ? padding : ' ', precision - (i)); \
s += precision - (i); \
} \
else { \
NEEDS(i); \
} \
} while (0);

#define FLAG_FOUND | ( | ) |  |

Value:
do { \
if (precision > 0) \
goto unknown; \
} while (0)

#define FMT | ( |  | def_pad,
|  |  | def_prec,
|  |  | fmt,
|  |  | val
| ) |  |

Value:
do { \
int l; \
if (precision <= 0) precision = (def_prec); \
if (flags & BIT_OF(LEFT)) precision = 1; \
l = snprintf(s, endp - s, \
((padding == '0' || (!padding && (def_pad) == '0')) ? "%0*"fmt : "%*"fmt), \
precision, (val)); \
if (l < 0) goto err; \
s += l; \
} while (0)

#define FMTV | ( |  | def_pad,
|  |  | def_prec,
|  |  | fmt,
|  |  | val
| ) |  |

Value:
do { \
VALUE tmp = (val); \
if (FIXNUM_P(tmp)) { \
FMT((def_pad), (def_prec), "l"fmt, FIX2LONG(tmp)); \
} \
else { \
VALUE args[2], result; \
size_t l; \
if (precision <= 0) precision = (def_prec); \
if (flags & BIT_OF(LEFT)) precision = 1; \
args[0] = INT2FIX(precision); \
args[1] = (val); \
if (padding == '0' || (!padding && (def_pad) == '0')) \
result = rb_str_format(2, args, rb_str_new2("%0*"fmt)); \
else \
result = rb_str_format(2, args, rb_str_new2("%*"fmt)); \
l = strlcpy(s, StringValueCStr(result), endp-s); \
if ((size_t)(endp-s) <= l) \
goto err; \
s += l; \
} \
} while (0)

#define ISO_DATE_EXT 1 /* %G and %g for year of ISO week */

Definition at line 76 of file strftime.c.

#define MAILHEADER_EXT 1 /* add %z for HHMM format */

Definition at line 75 of file strftime.c.

#define mod | ( |  | x,
|  |  | y
| ) |  | (rb_funcall((x), '%', 1, (y)))

Definition at line 155 of file strftime.c.

Referenced by rb_strftime_with_timespec(), and vtm2tm_noyear().

#define mul | ( |  | x,
|  |  | y
| ) |  | (rb_funcall((x), '*', 1, (y)))

Definition at line 152 of file strftime.c.

Referenced by rb_strftime_with_timespec().

#define NEEDS | ( |  | n) |  | do if (s >= endp || (n) >= endp - s - 1) goto err; while (0)

#define POSIX2_DATE 1 /* stuff in Posix 1003.2 date command */

Definition at line 73 of file strftime.c.

#define quo | ( |  | x,
|  |  | y
| ) |  | (rb_funcall((x), rb_intern("quo"), 1, (y)))

Definition at line 153 of file strftime.c.

#define range | ( |  | low,
|  |  | item,
|  |  | hi
| ) |  | max((low), min((item), (hi)))

#define STRFTIME | ( |  | fmt) |  |

Value:
do { \
i = rb_strftime_with_timespec(s, endp - s, (fmt), enc, vtm, timev, ts, gmt); \
if (!i) return 0; \
if (precision > i) {\
NEEDS(precision); \
memmove(s + precision - i, s, i);\
memset(s, padding ? padding : ' ', precision - i); \
s += precision; \
}\
else s += i; \
} while (0)

#define sub | ( |  | x,
|  |  | y
| ) |  | (rb_funcall((x), '-', 1, (y)))

Definition at line 151 of file strftime.c.

Referenced by rb_strftime_with_timespec().

#define SUNOS_EXT 1 /* stuff in SunOS strftime routine */

Definition at line 72 of file strftime.c.

#define SYSV_EXT 1 /* stuff in System V ascftime routine */

Definition at line 71 of file strftime.c.

#define TBUFSIZE 100

Referenced by rb_strftime_with_timespec().

#define VMS_EXT 1 /* include %v for VMS date format */

Definition at line 74 of file strftime.c.

## Function Documentation

adddecl | ( | static int iso8601wknum(); | ) |  |

Definition at line 104 of file strftime.c.

static int isleap | ( | long | year) |  |
| static

Definition at line 844 of file strftime.c.

Referenced by iso8601wknum().

static int iso8601wknum | ( | const struct tm * | timeptr) |  |
| static

Definition at line 879 of file strftime.c.

References isleap(), and weeknumber().

Referenced by iso8601wknum_v().

static int iso8601wknum_v | ( | const struct vtm * | vtm) |  |
| static

Definition at line 986 of file strftime.c.

References iso8601wknum(), and vtm2tm_noyear().

Referenced by rb_strftime_with_timespec().

static int max | ( | int | a,
|  | int | b
| ) |  |
| inline static

Definition at line 141 of file strftime.c.

Referenced by ary_join_0(), compile_array_(), econv_putback(), get_max_match_length(), optimize_node_left(), rand_int(), rand_random(), rand_range(), rb_method_entry_arity(), rb_proc_arity(), ruby_setenv(), set_mml(), tr_trans(), and vm_callee_setup_arg_complex().

size_t rb_strftime | ( | char * | s,
|  | size_t | maxsize,
|  | const char * | format,
|  | rb_encoding * | enc,
|  | const struct vtm * | vtm,
|  | VALUE | timev,
|  | int | gmt
| ) |  |

Definition at line 830 of file strftime.c.

References NULL, and rb_strftime_with_timespec().

Referenced by rb_strftime_alloc().

size_t rb_strftime_timespec | ( | char * | s,
|  | size_t | maxsize,
|  | const char * | format,
|  | rb_encoding * | enc,
|  | const struct vtm * | vtm,
|  | struct timespec * | ts,
|  | int | gmt
| ) |  |

Definition at line 836 of file strftime.c.

References Qnil, and rb_strftime_with_timespec().

Referenced by rb_strftime_alloc().

static size_t rb_strftime_with_timespec | ( | char * | s,
|  | size_t | maxsize,
|  | const char * | format,
|  | rb_encoding * | enc,
|  | const struct vtm * | vtm,
|  | VALUE | timev,
|  | struct timespec * | ts,
|  | int | gmt
| ) |  |
| static

Definition at line 165 of file strftime.c.

References add, args, BIT_OF, div, ECONV_INVALID_REPLACE, ECONV_UNDEF_REPLACE, err, errno, FILL_PADDING, FIX2LONG, FIXNUM_P, FLAG_FOUND, FMT, FMTV, vtm::hour, i, INT2FIX, ISLOWER, iso8601wknum_v(), ISUPPER, vtm::mday, vtm::min, mod, vtm::mon, mul, NEEDS, NULL, NUM2INT, NUM2LONG, PRI_TIMET_PREFIX, Qnil, range, rb_ascii8bit_encoding(), rb_funcall(), rb_intern, rb_locale_encoding(), rb_str_conv_enc_opts(), rb_str_format(), rb_str_new2, rb_str_new_cstr(), rb_usascii_encoding(), result, RSTRING_PTR, vtm::sec, snprintf, strchr(), STRFTIME, StringValueCStr, strlcpy(), strlen(), sub, TBUFSIZE, TOLOWER, TOUPPER, timespec::tv_nsec, timespec::tv_sec, vtm::utc_offset, vtm::wday, weeknumber_v(), vtm::yday, vtm::year, and vtm::zone.

Referenced by rb_strftime(), and rb_strftime_timespec().

static void vtm2tm_noyear | ( | const struct vtm * | vtm,
|  | struct tm * | result
| ) |  |
| static

Definition at line 851 of file strftime.c.

References FIX2INT, vtm::hour, INT2FIX, vtm::isdst, vtm::mday, vtm::min, mod, vtm::mon, NUM2LONG, vtm::sec, vtm::utc_offset, vtm::wday, vtm::yday, vtm::year, and vtm::zone.

Referenced by iso8601wknum_v(), and weeknumber_v().

static int weeknumber | ( | ) |  |
| static

Referenced by iso8601wknum(), and weeknumber_v().

static int weeknumber | ( | const struct tm * | timeptr,
|  | int | firstweekday
| ) |  |
| static

Definition at line 1000 of file strftime.c.

static int weeknumber_v | ( | const struct vtm * | vtm,
|  | int | firstweekday
| ) |  |
| static

Definition at line 1018 of file strftime.c.

References vtm2tm_noyear(), and weeknumber().

Referenced by rb_strftime_with_timespec().