Ruby 1.9.2p136(2010-12-25revision30365)

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

Defines | Functions

# strftime.c File Reference

`#include "ruby/ruby.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.

## Defines
#define | SYSV_EXT 1
#define | SUNOS_EXT 1
#define | POSIX2_DATE 1
#define | VMS_EXT 1
#define | MAILHEADER_EXT 1
#define | ISO_DATE_EXT 1
#define | POSIX_SEMANTICS 1
#define | adddecl(stuff) stuff
#define | const
#define | range(low, item, hi) max(low, min(item, hi))
#define | DLL_IMPORT
#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 | BIT_OF(n) (1U<<(n))
#define | FLAG_FOUND()
#define | NEEDS(n) do if (s + (n) >= endp - 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, const struct vtm *vtm, VALUE timev, struct timespec *ts, int gmt)
size_t | rb_strftime (char *s, size_t maxsize, const char *format, const struct vtm *vtm, VALUE timev, int gmt)
size_t | rb_strftime_timespec (char *s, size_t maxsize, const char *format, 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 (struct tm *timeptr) const
static int | iso8601wknum_v (const struct vtm *vtm)
static int | weeknumber (struct tm *timeptr, int firstweekday) const
static int | weeknumber_v (const struct vtm *vtm, int firstweekday)

## Define Documentation

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

Definition at line 183 of file strftime.c.

Referenced by init_heap(), onig_chain_link_add(), rb_str_associate(), and rb_strftime_with_timespec().

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

Definition at line 96 of file strftime.c.

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

Referenced by rb_strftime_with_timespec().

#define const

Definition at line 104 of file strftime.c.

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

Definition at line 187 of file strftime.c.

Referenced by BigDecimal_div(), BigDecimal_div2(), BigDecimal_divmod(), BigDecimal_mod(), fix_divide(), fix_divmod(), fixdivmod(), flo_divmod(), flodivmod(), rb_big_divide(), rb_big_divmod(), rb_strftime_with_timespec(), VpMidRound(), and VpVtoD().

#define DLL_IMPORT

Referenced by adddecl().

#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);

Referenced by rb_strftime_with_timespec().

#define FLAG_FOUND | ( |  | ) |

Value:

    do { \
                            if (precision > 0 || flags & (BIT_OF(LOCALE_E)|BIT_OF(LOCALE_O))) \
                                    goto unknown; \
                    } while (0)

Referenced by rb_strftime_with_timespec().

#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)

Referenced by rb_strftime_with_timespec().

#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)

Referenced by rb_strftime_with_timespec().

#define ISO_DATE_EXT 1

Definition at line 75 of file strftime.c.

#define MAILHEADER_EXT 1

Definition at line 74 of file strftime.c.

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

Definition at line 188 of file strftime.c.

Referenced by BigDecimal_div2(), BigDecimal_divmod(), BigDecimal_mod(), bigdivmod(), class_instance_method_list(), fix_divmod(), fix_mod(), fixdivmod(), flo_divmod(), flo_mod(), flodivmod(), rb_ary_flatten(), rb_ary_flatten_bang(), rb_big_divmod(), rb_class_inherited_p(), rb_mod_alias_method(), rb_mod_const_of(), rb_mod_define_method(), rb_mod_initialize(), rb_mod_remove_method(), rb_mod_undef_method(), rb_module_s_alloc(), rb_str_sum(), rb_strftime_with_timespec(), and vtm2tm_noyear().

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

Definition at line 185 of file strftime.c.

Referenced by rb_strftime_with_timespec().

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

Referenced by rb_strftime_with_timespec().

#define POSIX2_DATE 1

Definition at line 72 of file strftime.c.

#define POSIX_SEMANTICS 1

Definition at line 77 of file strftime.c.

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

Definition at line 186 of file strftime.c.

Referenced by rb_strftime_with_timespec().

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

Referenced by enc_succ_alnum_char(), iso2022jp_check_conv(), rb_range_new(), rb_reg_adjust_startpos(), rb_reg_search(), and rb_strftime_with_timespec().

#define STRFTIME | ( |  | fmt | ) |

Value:

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

Referenced by rb_strftime_with_timespec().

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

Definition at line 184 of file strftime.c.

Referenced by rb_str_index_m(), rb_str_rindex_m(), rb_str_substr(), and rb_strftime_with_timespec().

#define SUNOS_EXT 1

Definition at line 71 of file strftime.c.

#define SYSV_EXT 1

Definition at line 70 of file strftime.c.

#define VMS_EXT 1

Definition at line 73 of file strftime.c.

## Function Documentation

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

Definition at line 106 of file strftime.c.

References DLL_IMPORT.

static int isleap | ( | long | year | ) | `[static]`

Definition at line 908 of file strftime.c.

Referenced by iso8601wknum().

static int iso8601wknum | ( | struct tm * | timeptr | ) | const`[static]`

Definition at line 949 of file strftime.c.

References isleap(), and weeknumber().

Referenced by iso8601wknum_v().

static int iso8601wknum_v | ( | const struct vtm * | vtm | ) | `[static]`

Definition at line 1061 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 169 of file strftime.c.

Referenced by ary_join_0(), econv_putback(), get_max_match_length(), optimize_node_left(), rand_int(), random_rand(), ruby_setenv(), set_mml(), and tr_trans().

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

Definition at line 893 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,
|  | const struct vtm * | vtm,
|  | struct timespec * | ts,
|  | int | gmt
| ) |  |

Definition at line 899 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,
|  | const struct vtm * | vtm,
|  | VALUE | timev,
|  | struct timespec * | ts,
|  | int | gmt
| ) |  | `[static]`

Definition at line 193 of file strftime.c.

References add, BIT_OF, div, err, errno, FILL_PADDING, FIX2LONG, FIXNUM_P, FLAG_FOUND, FMT, FMTV, getenv(), gettimeofday(), vtm::hour, INT2FIX, ISLOWER, iso8601wknum_v(), ISUPPER, malloc, vtm::mday, vtm::min, mod, vtm::mon, mul, NEEDS, NULL, NUM2INT, NUM2LONG(), PRI_TIMET_PREFIX, quo, range, rb_funcall(), rb_intern, rb_str_format(), rb_str_new2(), realloc, result, vtm::sec, snprintf, strchr(), STRFTIME, StringValueCStr, strlcpy(), sub, time_t, TOLOWER, TOUPPER, timespec::tv_nsec, timespec::tv_sec, timezone::tz_minuteswest, 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 920 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 | ( | struct tm * | timeptr,
|  | int | firstweekday
| ) |  | const`[static]`

Definition at line 1076 of file strftime.c.

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

Definition at line 1100 of file strftime.c.

References vtm2tm_noyear(), and weeknumber().

Referenced by rb_strftime_with_timespec().