Ruby: ext/date/date_strftime.c File Reference

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

Macros | Functions
date_strftime.c File Reference
`#include "ruby/ruby.h"`
`#include "date_tmx.h"`
`#include <stdlib.h>`
`#include <string.h>`
`#include <ctype.h>`
`#include <errno.h>`

Go to the source code of this file.

## Macros
#define | range(low, item, hi) (item)
#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 >= 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
size_t | date_strftime (char *s, size_t maxsize, const char *format, const struct tmx *tmx)

## Macro Definition Documentation

## ◆ add

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

Definition at line 23 of file date_strftime.c.

## ◆ BIT_OF

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

## ◆ div

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

Definition at line 27 of file date_strftime.c.

## ◆ FILL_PADDING

#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);
BIT_OF
#define BIT_OF(n)
LEFT
@ LEFT
Definition: strftime.c:165

## ◆ FLAG_FOUND

#define FLAG_FOUND | ( |  | ) |

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

## ◆ FMT

#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)
snprintf
#define snprintf
Definition: subst.h:14
err
int err
Definition: win32.c:142
if
if((ID)(DISPID) nameid !=nameid)
Definition: win32ole.c:357

## ◆ FMTV

#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)
rb_str_new2
#define rb_str_new2
Definition: string.h:276
strlcpy
size_t strlcpy(char *, const char *, size_t)
Definition: strlcpy.c:29
INT2FIX
#define INT2FIX
Definition: long.h:48
FIX2LONG
#define FIX2LONG
Definition: long.h:46
StringValueCStr
#define StringValueCStr(v)
Definition: rstring.h:52
FIXNUM_P
#define FIXNUM_P
Definition: special_consts.h:44
rb_str_format
VALUE rb_str_format(int, const VALUE *, VALUE)
Definition: sprintf.c:214
VALUE
unsigned long VALUE
Definition: value.h:38

## ◆ mod

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

Definition at line 28 of file date_strftime.c.

## ◆ mul

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

Definition at line 25 of file date_strftime.c.

## ◆ NEEDS

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

## ◆ quo

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

Definition at line 26 of file date_strftime.c.

## ◆ range

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

Definition at line 21 of file date_strftime.c.

## ◆ STRFTIME

#define STRFTIME | ( |  | fmt | ) |

Value:
do { \
i = date_strftime_with_tmx(s, endp - s, (fmt), tmx); \
if (!i) return 0; \
if (flags & BIT_OF(UPPER)) \
upcase(s, i); \
if (!(flags & BIT_OF(LEFT)) && precision > i) { \
if (start + maxsize < s + precision) { \
errno = ERANGE; \
return 0; \
} \
memmove(s + precision - i, s, i); \
memset(s, padding ? padding : ' ', precision - i); \
s += precision; \
} \
else s += i; \
} while (0)
UPPER
@ UPPER
Definition: strftime.c:165
tmx
Definition: date_tmx.h:24

## ◆ sub

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

Definition at line 24 of file date_strftime.c.

## Function Documentation

## ◆ date_strftime()

size_t date_strftime | ( | char * | s,
|  | size_t | maxsize,
|  | const char * | format,
|  | const struct tmx * | tmx
| ) |  |

Definition at line 628 of file date_strftime.c.